geohydra 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -1
  3. data/.travis.yml +1 -2
  4. data/Gemfile +1 -8
  5. data/Gemfile.lock +87 -102
  6. data/README.md +2 -2
  7. data/VERSION +1 -1
  8. data/bin/accession.rb +99 -89
  9. data/bin/assemble.rb +288 -247
  10. data/bin/assemble_data.rb +54 -51
  11. data/bin/assemble_placenames.rb +85 -85
  12. data/bin/build_stage_options.rb +24 -18
  13. data/bin/derive_wgs84.rb +65 -66
  14. data/bin/extract_thumbnail.rb +38 -37
  15. data/bin/geo2mods.rb +78 -0
  16. data/bin/geohydra +14 -5
  17. data/bin/ingest_arcgis.rb +80 -60
  18. data/bin/iso2geo.rb +64 -0
  19. data/bin/loader_postgis.rb +121 -227
  20. data/bin/run_task.rb +23 -0
  21. data/bin/sync_geoserver_metadata.rb +132 -127
  22. data/bin/xsltproc-saxon +6 -0
  23. data/geohydra.gemspec +6 -4
  24. data/lib/geohydra.rb +5 -0
  25. data/lib/geohydra/accession.rb +24 -13
  26. data/lib/geohydra/{arcgis_to_iso19139_fc.xsl → arcgis_to_iso19110.xsl} +0 -0
  27. data/lib/geohydra/gazetteer.csv +842 -36
  28. data/lib/geohydra/gazetteer.rb +48 -24
  29. data/lib/geohydra/mods2geoblacklight.xsl +248 -0
  30. data/lib/geohydra/mods2ogp.xsl +5 -8
  31. data/lib/geohydra/transform.rb +8 -2
  32. data/lib/geohydra/utils.rb +6 -0
  33. data/lib/geohydra/workflow/gisAssemblyWF.rb +109 -0
  34. data/lib/geohydra/workflow/gisAssemblyWF.xml +85 -0
  35. data/lib/geohydra/workflow/gisDeliveryWF.rb +33 -0
  36. data/lib/geohydra/workflow/gisDeliveryWF.xml +36 -0
  37. data/lib/geohydra/workflow/gisDiscoveryWF.rb +55 -0
  38. data/lib/geohydra/workflow/gisDiscoveryWF.xml +28 -0
  39. data/lib/geohydra/workflow/task.rb +82 -0
  40. data/ogp/README.md +350 -0
  41. data/ogp/download.rb +92 -0
  42. data/ogp/fgdc2mods.sh +9 -0
  43. data/ogp/fgdc2mods.xsl +884 -0
  44. data/ogp/ingest.rb +48 -0
  45. data/ogp/select.rb +20 -0
  46. data/ogp/transform.rb +354 -0
  47. data/ogp/validate.rb +182 -0
  48. data/{bin → scripts}/ingest_tufts.rb +0 -0
  49. data/scripts/iso2html/doit.sh +15 -0
  50. data/scripts/iso2html/main.css +66 -0
  51. data/scripts/iso2html/pacioos-iso-html.xsl +1749 -0
  52. data/scripts/iso2html/utils/replace-newlines.xsl +97 -0
  53. data/scripts/iso2html/utils/replace-string.xsl +80 -0
  54. data/scripts/iso2html/utils/strip-digits.xsl +60 -0
  55. data/{bin → scripts}/loader.rb +0 -0
  56. data/scripts/rename_shapefiles.rb +5 -0
  57. data/scripts/render_gazetteer.rb +36 -0
  58. data/{bin → scripts}/seed.rb +0 -0
  59. data/{bin → scripts}/solr_indexer.rb +0 -0
  60. data/scripts/status.csv +253 -0
  61. data/scripts/status.rb +32 -0
  62. data/{bin → scripts}/validate_data.rb +1 -1
  63. data/solr/kurma-app-dev/conf/lang/stopwords_en.txt +34 -0
  64. data/solr/kurma-app-dev/conf/protwords.txt +21 -0
  65. data/solr/kurma-app-dev/conf/schema.xml +156 -0
  66. data/solr/kurma-app-dev/conf/solrconfig.xml +161 -0
  67. data/solr/kurma-app-dev/conf/synonyms.txt +29 -0
  68. data/solr/kurma-app-dev/purge.sh +8 -0
  69. data/solr/kurma-app-test/conf/lang/stopwords_en.txt +34 -0
  70. data/solr/kurma-app-test/conf/protwords.txt +21 -0
  71. data/solr/kurma-app-test/conf/schema.xml +158 -0
  72. data/solr/kurma-app-test/conf/solrconfig.xml +161 -0
  73. data/solr/kurma-app-test/conf/synonyms.txt +29 -0
  74. data/solr/kurma-app-test/deploy.sh +15 -0
  75. data/solr/kurma-app-test/purge.sh +8 -0
  76. data/solr/ogp-dev/purge.sh +1 -2
  77. data/spec/fixtures/bw938nk9584/temp/{TRIPURA-iso19139-fc.xml → TRIPURA-iso19110.xml} +0 -0
  78. data/spec/fixtures/cc142xj8436/temp/{HARYANA-iso19139-fc.xml → HARYANA-iso19110.xml} +0 -0
  79. data/spec/fixtures/cg716wc7949/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  80. data/spec/fixtures/cm007pv9601/temp/{MEGHALAYA-iso19139-fc.xml → MEGHALAYA-iso19110.xml} +0 -0
  81. data/spec/fixtures/cp055nb0189/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  82. data/spec/fixtures/cs838pw3418/temp/{OIL_GAS_FIELDS-iso19139-fc.xml → OIL_GAS_FIELDS-iso19110.xml} +0 -0
  83. data/spec/fixtures/dd308sy5843/temp/{ORISSA-iso19139-fc.xml → ORISSA-iso19110.xml} +0 -0
  84. data/spec/fixtures/dd452vk1873/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  85. data/spec/fixtures/dg850pt1796/temp/{STATE1951-iso19139-fc.xml → STATE1951-iso19110.xml} +0 -0
  86. data/spec/fixtures/dn744tf5427/temp/{DISTRICT1991-iso19139-fc.xml → DISTRICT1991-iso19110.xml} +0 -0
  87. data/spec/fixtures/dq603nz8402/temp/{STATE2001-iso19139-fc.xml → STATE2001-iso19110.xml} +0 -0
  88. data/spec/fixtures/dv609zt4699/temp/{ASSAM-iso19139-fc.xml → ASSAM-iso19110.xml} +0 -0
  89. data/spec/fixtures/dz222hw0585/temp/{PUNJAB-iso19139-fc.xml → PUNJAB-iso19110.xml} +0 -0
  90. data/spec/fixtures/fd673qb9705/temp/{STATE1971-iso19139-fc.xml → STATE1971-iso19110.xml} +0 -0
  91. data/spec/fixtures/fg451wp8917/temp/{SIKKIM-iso19139-fc.xml → SIKKIM-iso19110.xml} +0 -0
  92. data/spec/fixtures/fh247yz0156/temp/{RAJASTHAN-iso19139-fc.xml → RAJASTHAN-iso19110.xml} +0 -0
  93. data/spec/fixtures/fs487vd1465/temp/{CHHATTISGARH-iso19139-fc.xml → CHHATTISGARH-iso19110.xml} +0 -0
  94. data/spec/fixtures/fs591bn3317/temp/{HIMACHAL_PRADESH-iso19139-fc.xml → HIMACHAL_PRADESH-iso19110.xml} +0 -0
  95. data/spec/fixtures/fw920bc5473/temp/{PLSS_TWN-iso19139-fc.xml → PLSS_TWN-iso19110.xml} +0 -0
  96. data/spec/fixtures/gj831wj3625/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  97. data/spec/fixtures/gp075nv3265/temp/{PONDICHERRY-iso19139-fc.xml → PONDICHERRY-iso19110.xml} +0 -0
  98. data/spec/fixtures/gv800hj8141/temp/{BIHAR-iso19139-fc.xml → BIHAR-iso19110.xml} +0 -0
  99. data/spec/fixtures/gw520gz6339/temp/{DADRA_NAGAR_HAVELI_PT-iso19139-fc.xml → DADRA_NAGAR_HAVELI_PT-iso19110.xml} +0 -0
  100. data/spec/fixtures/gy054hz1045/temp/{HARYANA-iso19139-fc.xml → HARYANA-iso19110.xml} +0 -0
  101. data/spec/fixtures/gz352mw6982/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  102. data/spec/fixtures/hb489vm9892/temp/{DISTRICT1981-iso19139-fc.xml → DISTRICT1981-iso19110.xml} +0 -0
  103. data/spec/fixtures/hw125dq0418/temp/{DELHI-iso19139-fc.xml → DELHI-iso19110.xml} +0 -0
  104. data/spec/fixtures/hw892mn4587/temp/{KERALA-iso19139-fc.xml → KERALA-iso19110.xml} +0 -0
  105. data/spec/fixtures/jb371hz3868/temp/{INCOME-iso19139-fc.xml → INCOME-iso19110.xml} +0 -0
  106. data/spec/fixtures/jc017yk9928/temp/{KARNATAKA-iso19139-fc.xml → KARNATAKA-iso19110.xml} +0 -0
  107. data/spec/fixtures/jf841ys4828/temp/{ANDHRA_PRADESH-iso19139-fc.xml → ANDHRA_PRADESH-iso19110.xml} +0 -0
  108. data/spec/fixtures/jh802mp2160/temp/{DELHI_PT-iso19139-fc.xml → DELHI_PT-iso19110.xml} +0 -0
  109. data/spec/fixtures/jj806fc3801/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  110. data/spec/fixtures/jq835yn7161/temp/{HIMACHAL_PRADESH-iso19139-fc.xml → HIMACHAL_PRADESH-iso19110.xml} +0 -0
  111. data/spec/fixtures/jr455pt6676/temp/{TAMILNADU-iso19139-fc.xml → TAMILNADU-iso19110.xml} +0 -0
  112. data/spec/fixtures/js637zp2537/temp/{BIHAR-iso19139-fc.xml → BIHAR-iso19110.xml} +0 -0
  113. data/spec/fixtures/jv502wg9611/temp/{GOA-iso19139-fc.xml → GOA-iso19110.xml} +0 -0
  114. data/spec/fixtures/jw462ck6560/temp/{JAMMU_KASHMIR-iso19139-fc.xml → JAMMU_KASHMIR-iso19110.xml} +0 -0
  115. data/spec/fixtures/kj800fb6273/temp/{STATE2011-iso19139-fc.xml → STATE2011-iso19110.xml} +0 -0
  116. data/spec/fixtures/km504zq3948/temp/{HIMACHAL_PRADESH-iso19139-fc.xml → HIMACHAL_PRADESH-iso19110.xml} +0 -0
  117. data/spec/fixtures/ks297fy1411/temp/{OFFSH_BLOCKS-iso19139-fc.xml → OFFSH_BLOCKS-iso19110.xml} +0 -0
  118. data/spec/fixtures/md358hy5049/temp/{MIZORAM-iso19139-fc.xml → MIZORAM-iso19110.xml} +0 -0
  119. data/spec/fixtures/mg745bq0193/temp/{MADHYA_PRADESH-iso19139-fc.xml → MADHYA_PRADESH-iso19110.xml} +0 -0
  120. data/spec/fixtures/mh187yx3536/temp/{WEST_BENGAL-iso19139-fc.xml → WEST_BENGAL-iso19110.xml} +0 -0
  121. data/spec/fixtures/mk488yn6694/temp/{GUJARAT-iso19139-fc.xml → GUJARAT-iso19110.xml} +0 -0
  122. data/spec/fixtures/my216kp3008/temp/{DELHI-iso19139-fc.xml → DELHI-iso19110.xml} +0 -0
  123. data/spec/fixtures/my504nz9827/temp/{JAMMU_KASHMIR-iso19139-fc.xml → JAMMU_KASHMIR-iso19110.xml} +0 -0
  124. data/spec/fixtures/ng819jm8700/temp/{MANIPUR-iso19139-fc.xml → MANIPUR-iso19110.xml} +0 -0
  125. data/spec/fixtures/np020jq2139/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  126. data/spec/fixtures/ns377mt1608/temp/{STATE1991-iso19139-fc.xml → STATE1991-iso19110.xml} +0 -0
  127. data/spec/fixtures/nw926np8508/temp/{metadata.iso19139-fc.xml → metadata.iso19110.xml} +0 -0
  128. data/spec/fixtures/ny358rm8559/temp/{TRIPURA-iso19139-fc.xml → TRIPURA-iso19110.xml} +0 -0
  129. data/spec/fixtures/nz176rm8192/temp/{DISTRICT2011-iso19139-fc.xml → DISTRICT2011-iso19110.xml} +0 -0
  130. data/spec/fixtures/nz252rq2252/temp/{UTTAR_PRADESH-iso19139-fc.xml → UTTAR_PRADESH-iso19110.xml} +0 -0
  131. data/spec/fixtures/pd902kb3348/temp/{MADHYA_PRADESH-iso19139-fc.xml → MADHYA_PRADESH-iso19110.xml} +0 -0
  132. data/spec/fixtures/pz792fz1776/temp/{MAHARASHTRA-iso19139-fc.xml → MAHARASHTRA-iso19110.xml} +0 -0
  133. data/spec/fixtures/qb767ss4042/temp/{UTTAR_PRADESH-iso19139-fc.xml → UTTAR_PRADESH-iso19110.xml} +0 -0
  134. data/spec/fixtures/qc091qw0570/temp/{GUJARAT-iso19139-fc.xml → GUJARAT-iso19110.xml} +0 -0
  135. data/spec/fixtures/qc652vr7204/temp/{ANDHRA_PRADESH_PT-iso19139-fc.xml → ANDHRA_PRADESH_PT-iso19110.xml} +0 -0
  136. data/spec/fixtures/qk786js7484/temp/{DISTRICT1961-iso19139-fc.xml → DISTRICT1961-iso19110.xml} +0 -0
  137. data/spec/fixtures/qn676pg6767/temp/{GOA-iso19139-fc.xml → GOA-iso19110.xml} +0 -0
  138. data/spec/fixtures/qr255jh4074/temp/{LOKSABHA_14-iso19139-fc.xml → LOKSABHA_14-iso19110.xml} +0 -0
  139. data/spec/fixtures/qr374kj4827/temp/{ASSAM-iso19139-fc.xml → ASSAM-iso19110.xml} +0 -0
  140. data/spec/fixtures/qy162js1748/temp/{CHHATTISGARH-iso19139-fc.xml → CHHATTISGARH-iso19110.xml} +0 -0
  141. data/spec/fixtures/rd446vf2633/temp/{NAGALAND-iso19139-fc.xml → NAGALAND-iso19110.xml} +0 -0
  142. data/spec/fixtures/rf389hf2983/temp/{CHHATTISGARH_PT-iso19139-fc.xml → CHHATTISGARH_PT-iso19110.xml} +0 -0
  143. data/spec/fixtures/rf859ff4582/temp/{JHARKHAND-iso19139-fc.xml → JHARKHAND-iso19110.xml} +0 -0
  144. data/spec/fixtures/rh343ds8931/temp/{BIHAR-iso19139-fc.xml → BIHAR-iso19110.xml} +0 -0
  145. data/spec/fixtures/rn815xk8157/temp/{SIKKIM-iso19139-fc.xml → SIKKIM-iso19110.xml} +0 -0
  146. data/spec/fixtures/rq653sz4470/temp/{CHHATTISGARH-iso19139-fc.xml → CHHATTISGARH-iso19110.xml} +0 -0
  147. data/spec/fixtures/rt625ws6022/temp/{GULF_FAIRWAYS-iso19139-fc.xml → GULF_FAIRWAYS-iso19110.xml} +0 -0
  148. data/spec/fixtures/sc330vf4259/temp/{JHARKHAND-iso19139-fc.xml → JHARKHAND-iso19110.xml} +0 -0
  149. data/spec/fixtures/sq479mx3086/temp/{OFFSH_PLATF-iso19139-fc.xml → OFFSH_PLATF-iso19110.xml} +0 -0
  150. data/spec/fixtures/sr686bm4098/temp/{DAMAN_DIU_PT-iso19139-fc.xml → DAMAN_DIU_PT-iso19110.xml} +0 -0
  151. data/spec/fixtures/sv303sh5583/temp/{ARUNACHAL_PRADESH-iso19139-fc.xml → ARUNACHAL_PRADESH-iso19110.xml} +0 -0
  152. data/spec/fixtures/sy319nh8520/temp/{GUJARAT-iso19139-fc.xml → GUJARAT-iso19110.xml} +0 -0
  153. data/spec/fixtures/td363vx2792/temp/{HIMACHAL_PRADESH_PT-iso19139-fc.xml → HIMACHAL_PRADESH_PT-iso19110.xml} +0 -0
  154. data/spec/fixtures/tf374bd2484/temp/{DISTRICT1951-iso19139-fc.xml → DISTRICT1951-iso19110.xml} +0 -0
  155. data/spec/fixtures/tj797mj7877/temp/{LOKSABHA_15-iso19139-fc.xml → LOKSABHA_15-iso19110.xml} +0 -0
  156. data/spec/fixtures/tv060wq5179/temp/{ASSAM-iso19139-fc.xml → ASSAM-iso19110.xml} +0 -0
  157. data/spec/fixtures/tv536bn1915/temp/{ARUNACHAL_PRADESH-iso19139-fc.xml → ARUNACHAL_PRADESH-iso19110.xml} +0 -0
  158. data/spec/fixtures/tz359cc2977/temp/{MANIPUR-iso19139-fc.xml → MANIPUR-iso19110.xml} +0 -0
  159. data/spec/fixtures/vb525my6511/temp/{UTTARAKHAND-iso19139-fc.xml → UTTARAKHAND-iso19110.xml} +0 -0
  160. data/spec/fixtures/vh802fs4240/temp/{PONDICHERRY-iso19139-fc.xml → PONDICHERRY-iso19110.xml} +0 -0
  161. data/spec/fixtures/vk120xn2474/temp/{PLSS_SEC-iso19139-fc.xml → PLSS_SEC-iso19110.xml} +0 -0
  162. data/spec/fixtures/vn439bc7316/temp/{KERALA-iso19139-fc.xml → KERALA-iso19110.xml} +0 -0
  163. data/spec/fixtures/vq745jk0695/temp/{MEGHALAYA-iso19139-fc.xml → MEGHALAYA-iso19110.xml} +0 -0
  164. data/spec/fixtures/vr593vj7147/temp/{ANDHRA_PRADESH-iso19139-fc.xml → ANDHRA_PRADESH-iso19110.xml} +0 -0
  165. data/spec/fixtures/vw911qb5271/temp/{DISTRICT2001-iso19139-fc.xml → DISTRICT2001-iso19110.xml} +0 -0
  166. data/spec/fixtures/wg680pz0365/temp/{ANDHRA_PRADESH-iso19139-fc.xml → ANDHRA_PRADESH-iso19110.xml} +0 -0
  167. data/spec/fixtures/wg761xn1926/temp/{HARYANA-iso19139-fc.xml → HARYANA-iso19110.xml} +0 -0
  168. data/spec/fixtures/wh870qw1934/temp/{PUNJAB-iso19139-fc.xml → PUNJAB-iso19110.xml} +0 -0
  169. data/spec/fixtures/wk775mm4673/temp/{MAHARASHTRA-iso19139-fc.xml → MAHARASHTRA-iso19110.xml} +0 -0
  170. data/spec/fixtures/ws171yz2165/temp/{ARUNACHAL_PRADESH_PT-iso19139-fc.xml → ARUNACHAL_PRADESH_PT-iso19110.xml} +0 -0
  171. data/spec/fixtures/wt473hz7153/temp/{CHANDIGARH_PT-iso19139-fc.xml → CHANDIGARH_PT-iso19110.xml} +0 -0
  172. data/spec/fixtures/ww217dj0457/temp/{CO2_PIPE-iso19139-fc.xml → CO2_PIPE-iso19110.xml} +0 -0
  173. data/spec/fixtures/wy875pk9849/temp/{STATE1961-iso19139-fc.xml → STATE1961-iso19110.xml} +0 -0
  174. data/spec/fixtures/xb018tk2042/temp/{STATE1981-iso19139-fc.xml → STATE1981-iso19110.xml} +0 -0
  175. data/spec/fixtures/xg539vw8586/temp/{ORISSA-iso19139-fc.xml → ORISSA-iso19110.xml} +0 -0
  176. data/spec/fixtures/xv475kp4644/temp/{ASSAM_PT-iso19139-fc.xml → ASSAM_PT-iso19110.xml} +0 -0
  177. data/spec/fixtures/xy096gc2959/temp/{GOA-iso19139-fc.xml → GOA-iso19110.xml} +0 -0
  178. data/spec/fixtures/xz518gz3362/temp/{UTTARAKHAND-iso19139-fc.xml → UTTARAKHAND-iso19110.xml} +0 -0
  179. data/spec/fixtures/yh986wy4737/temp/{NAGALAND-iso19139-fc.xml → NAGALAND-iso19110.xml} +0 -0
  180. data/spec/fixtures/yn187fq4474/temp/{KARNATAKA-iso19139-fc.xml → KARNATAKA-iso19110.xml} +0 -0
  181. data/spec/fixtures/yn236mw3250/temp/{TAMILNADU-iso19139-fc.xml → TAMILNADU-iso19110.xml} +0 -0
  182. data/spec/fixtures/yz596nz0112/temp/{WEST_BENGAL-iso19139-fc.xml → WEST_BENGAL-iso19110.xml} +0 -0
  183. data/spec/fixtures/zk596gy7380/temp/{DISTRICT1971-iso19139-fc.xml → DISTRICT1971-iso19110.xml} +0 -0
  184. data/spec/fixtures/zn452hh7431/temp/{RAJASTHAN-iso19139-fc.xml → RAJASTHAN-iso19110.xml} +0 -0
  185. data/spec/fixtures/zt093fw6519/temp/{MIZORAM-iso19139-fc.xml → MIZORAM-iso19110.xml} +0 -0
  186. data/spec/fixtures/zv925hd6723/temp/{OGWELLS-iso19139-fc.xml → OGWELLS-iso19110.xml} +0 -0
  187. data/spec/fixtures/zy658cr1728/temp/{ANDAMAAN_NICOBAR_PT-iso19139-fc.xml → ANDAMAAN_NICOBAR_PT-iso19110.xml} +0 -0
  188. data/spec/fixtures/zz943vx1492/temp/{BASINS-iso19139-fc.xml → BASINS-iso19110.xml} +0 -0
  189. data/spec/unit/gazetteer_spec.rb +100 -35
  190. data/spec/unit/task_spec.rb +68 -0
  191. data/spec/unit/transform_spec.rb +1 -1
  192. data/spec/unit/utils_spec.rb +17 -3
  193. data/workflow.rb +35 -0
  194. metadata +323 -316
@@ -3,47 +3,48 @@
3
3
  require 'optparse'
4
4
  require 'geohydra'
5
5
 
6
- def do_file fn, flags
7
- if fn =~ %r{^(.*)\.(shp|tif)\.xml$}i
8
- puts "Processing #{fn} for JPEG" if flags[:verbose]
9
- GeoHydra::Transform.extract_thumbnail fn, File.join(File.dirname(fn), 'preview.jpg')
10
- else
11
- raise OptionParser::InvalidOption, "File <#{fn}> is not ESRI metadata format"
6
+ class ExtractThumbnail < GeoHydra::Process
7
+ def do_file fn, flags
8
+ if fn =~ %r{^(.*)\.(shp|tif)\.xml$}i
9
+ puts "Processing #{fn} for JPEG" if flags[:verbose]
10
+ GeoHydra::Transform.extract_thumbnail fn, File.join(File.dirname(fn), 'preview.jpg')
11
+ else
12
+ raise OptionParser::InvalidOption, "File <#{fn}> is not ESRI metadata format"
13
+ end
12
14
  end
13
- end
14
15
 
15
- flags = {
16
- :datadir => '.',
17
- :recurse => false,
18
- :verbose => false
19
- }
16
+ def run(args)
17
+ flags = {
18
+ :datadir => '.',
19
+ :recurse => false,
20
+ :verbose => false
21
+ }
20
22
 
21
- optparse = OptionParser.new do |opts|
22
- opts.banner = <<EOM
23
- Usage: #{File.basename(__FILE__)} [options] [fn [fn...]]
23
+ optparse = OptionParser.new do |opts|
24
+ opts.banner = <<EOM
25
+ Usage: #{File.basename(__FILE__)} [options] [fn [fn...]]
24
26
  EOM
25
- opts.on("-d", "--dir DIR", "Process all files in DIR (default: #{flags[:datadir]})") do |v|
26
- flags[:datadir] = v
27
- end
28
- opts.on("-r", "--recursive", "Process all files recurvisely") do |v|
29
- flags[:recurse] = true
30
- end
31
-
32
- opts.on("-v", "--verbose", "Run verbosely") do |v|
33
- flags[:verbose] = true
27
+ opts.on("-d", "--dir DIR", "Process all files in DIR (default: #{flags[:datadir]})") do |v|
28
+ flags[:datadir] = v
29
+ end
30
+ opts.on("-r", "--recursive", "Process all files recurvisely") do |v|
31
+ flags[:recurse] = true
32
+ end
33
+
34
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
35
+ flags[:verbose] = true
36
+ end
37
+ end
38
+
39
+ optparse.parse!(args)
40
+ if args.empty?
41
+ raise OptionParser::InvalidOption, flags[:datadir] + ' not a directory' unless File.directory?(flags[:datadir])
42
+ Dir.glob(flags[:datadir] + (flags[:recurse] ? '/**/*.shp.xml' : '/*.shp.xml')).each {|fn| do_file fn, flags }
43
+ else
44
+ args.each {|fn| do_file fn, flags }
45
+ end
34
46
  end
35
47
  end
36
48
 
37
- begin
38
- optparse.parse!
39
- if ARGV.empty?
40
- raise OptionParser::InvalidOption, flags[:datadir] + ' not a directory' unless File.directory?(flags[:datadir])
41
- Dir.glob(flags[:datadir] + (flags[:recurse] ? '/**/*.shp.xml' : '/*.shp.xml')).each {|fn| do_file fn, flags }
42
- else
43
- ARGV.each {|fn| do_file fn, flags }
44
- end
45
- rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
46
- $stderr.puts e
47
- $stderr.puts optparse
48
- exit(-1)
49
- end
49
+ ExtractThumbnail.new.run(ARGV)
50
+
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ require File.expand_path(File.dirname(__FILE__) + '/../config/boot')
4
+ require 'optparse'
5
+ require 'json'
6
+
7
+ class Geo2MODS < GeoHydra::Process
8
+ def main(flags)
9
+ defaultGeometryType = 'Polygon'
10
+ defaultZipName = 'data.zip'
11
+ purl, ifn, optfn, ofn = flags[:purl], flags[:geoMetadata], flags[:geoOptions], flags[:descMetadata]
12
+
13
+ puts "Processing #{purl} #{ifn}" if flags[:verbose]
14
+
15
+ puts "Loading extra out-of-band options #{optfn}" if flags[:debug]
16
+ if not optfn.nil? and File.exist?(optfn)
17
+ h = JSON.parse(File.read(optfn))
18
+ flags = flags.merge(h).symbolize_keys
19
+ ap({:optfn => optfn, :h => h, :flags => flags}) if flags[:debug]
20
+ else
21
+ puts "WARNING: missing options .json parameters: #{optfn}"
22
+ flags[:geometryType] ||= defaultGeometryType # XXX: placeholder
23
+ end
24
+
25
+ # Load datastream
26
+ geoMetadataDS = Dor::GeoMetadataDS.from_xml File.read(ifn)
27
+ geoMetadataDS.geometryType = flags[:geometryType] || defaultGeometryType
28
+ geoMetadataDS.zipName = defaultZipName
29
+ geoMetadataDS.purl = purl
30
+ ap({:geoMetadataDS => geoMetadataDS}) if flags[:debug]
31
+
32
+ # MODS from GeoMetadataDS
33
+ puts "Generating #{flags[:descMetadata]}" if flags[:verbose]
34
+ File.open(flags[:descMetadata], 'wb') do |f|
35
+ f << geoMetadataDS.to_mods.to_xml(:index => 2)
36
+ end
37
+ end
38
+
39
+ # __MAIN__
40
+ def run(args)
41
+ flags = {
42
+ :debug => false,
43
+ :verbose => false
44
+ }
45
+
46
+ OptionParser.new do |opts|
47
+ opts.banner = <<EOM
48
+ Usage: #{File.basename(__FILE__)} [options]
49
+ EOM
50
+ opts.on('-v', '--verbose', 'Run verbosely') do |v|
51
+ flags[:debug] = true if flags[:verbose]
52
+ flags[:verbose] = true
53
+ end
54
+ opts.on('--purl URI', "PURL with druid") do |v|
55
+ flags[:purl] = v
56
+ end
57
+ opts.on('--geoMetadata FILE', "Input file with ISO 19139/19110 XML") do |v|
58
+ flags[:geoMetadata] = v
59
+ end
60
+ opts.on('--geoOptions FILE', "Input file with JSON flags") do |v|
61
+ flags[:geoOptions] = v
62
+ end
63
+ opts.on('--descMetadata FILE', "Output file with MODS XML") do |v|
64
+ flags[:descMetadata] = v
65
+ end
66
+ end.parse!(args)
67
+
68
+ %w{purl geoMetadata descMetadata}.each do |k|
69
+ raise ArgumentError, "Missing required --#{k} flag" if flags[k.to_sym].nil?
70
+ end
71
+
72
+ ap({:flags => flags}) if flags[:debug]
73
+ main flags
74
+ end
75
+ end
76
+
77
+ # __MAIN__
78
+ Geo2MODS.new.run(ARGV)
@@ -1,11 +1,20 @@
1
1
  #!/bin/bash
2
2
 
3
- if [ $# -eq 0 ]; then
4
- echo "Usage: geohydra command [flags]"
3
+ usage() {
4
+ echo "Usage:"
5
+ echo " geohydra command [flags]"
6
+ echo " geohydra help"
7
+ echo "Commands:"
8
+ ls bin/*.rb | sed -e 's/^bin./ /' -e 's/.rb$//'
5
9
  exit -1
6
- fi
10
+ }
7
11
 
8
- fn=$1
12
+ [ $# -eq 0 ] && usage
13
+
14
+ fn=`basename $1 .rb`
9
15
  shift
10
16
 
11
- bundle exec bin/$fn.rb $*
17
+ [ $fn = '--help' -o $fn = 'help' ] && usage
18
+ [ ! -x bin/$fn.rb ] && echo "ERROR: Invalid command: Missing bin/$fn.rb" && usage
19
+
20
+ bundle exec bin/$fn.rb $@
@@ -4,74 +4,94 @@ require File.expand_path(File.dirname(__FILE__) + '/../config/boot')
4
4
  require 'optparse'
5
5
  require 'fileutils'
6
6
 
7
- def extract_thumbnail fn, flags
8
- if fn =~ %r{^(.*)\.(shp|tif)\.xml$}i or File.basename(fn) == 'metadata.xml'
9
- puts "Processing #{fn} for JPEG" if flags[:verbose]
10
- GeoHydra::Transform.extract_thumbnail fn, File.join(File.dirname(fn), 'preview.jpg')
11
- else
12
- raise OptionParser::InvalidOption, "File <#{fn}> is not ESRI metadata format"
7
+ class IngestArcGIS < GeoHydra::Process
8
+ def extract_thumbnail fn, flags
9
+ if fn =~ %r{^(.*)\.(shp|tif)\.xml$}i or File.basename(fn) == 'metadata.xml'
10
+ puts "Processing #{fn} for JPEG" if flags[:verbose]
11
+ thumbnail_fn = File.join(File.dirname(fn), 'preview.jpg')
12
+ puts "Writing to #{thumbnail_fn}" if flags[:debug]
13
+ GeoHydra::Transform.extract_thumbnail fn, thumbnail_fn
14
+ else
15
+ raise OptionParser::InvalidOption, "File <#{fn}> is not ESRI metadata format"
16
+ end
13
17
  end
14
- end
15
18
 
16
- def process_file fn, flags
17
- puts "Processing #{fn}" if flags[:verbose]
18
- if fn =~ %r{^(.*).(shp|tif).xml$}
19
- ofn = $1 + '-iso19139.xml'
20
- ofn_fc = $1 + '-iso19139-fc.xml'
21
- elsif File.basename(fn) == 'metadata.xml'
22
- ofn = File.join(File.dirname(fn), 'metadata.iso19139.xml')
23
- ofn_fc = File.join(File.dirname(fn), 'metadata.iso19139-fc.xml')
24
- else
25
- raise OptionParser::InvalidOption, "File <#{fn}> is not named correctly"
26
- end
19
+ def process_file fn, flags
20
+ puts "Processing #{fn}" if flags[:verbose]
21
+ if fn =~ %r{^(.*).(shp|tif).xml$}
22
+ ofn = $1 + '-iso19139.xml'
23
+ ofn_fc = $1 + '-iso19110.xml'
24
+ ofn_fgdc = $1 + '-fgdc.xml'
25
+ elsif File.basename(fn) == 'metadata.xml'
26
+ ofn = File.join(File.dirname(fn), 'metadata.iso19139.xml')
27
+ ofn_fc = File.join(File.dirname(fn), 'metadata.iso19110.xml')
28
+ ofn_fgdc = File.join(File.dirname(fn), 'metadata.fgdc.xml')
29
+ else
30
+ raise OptionParser::InvalidOption, "File <#{fn}> is not named correctly"
31
+ end
27
32
 
28
- ap({:fn => fn, :ofn => ofn, :ofn_fc => ofn_fc}) if flags[:debug]
29
- unless FileUtils.uptodate?(ofn, [fn]) and FileUtils.uptodate?(ofn_fc, [fn])
30
- GeoHydra::Transform.from_arcgis fn, ofn, ofn_fc
31
- extract_thumbnail(fn, flags)
32
- dstdir = "#{File.dirname(fn)}/../content/"
33
- FileUtils.mkdir_p(dstdir) unless File.directory?(dstdir)
34
- system("mv #{File.dirname(fn)}/*.jpg #{dstdir}/")
33
+ if flags[:rebuild] or not (FileUtils.uptodate?(ofn, [fn]) and FileUtils.uptodate?(ofn_fc, [fn]))
34
+ ap({:fn => fn, :ofn => ofn, :ofn_fc => ofn_fc, :ofn_fgdc => ofn_fgdc}) if flags[:debug]
35
+ begin
36
+ GeoHydra::Transform.from_arcgis fn, ofn, ofn_fc, ofn_fgdc
37
+ extract_thumbnail(fn, flags)
38
+ if flags[:mv_jpg]
39
+ dstdir = "#{File.dirname(fn)}/../content/"
40
+ FileUtils.mkdir_p(dstdir) unless File.directory?(dstdir)
41
+ system("mv #{File.dirname(fn)}/*.jpg #{dstdir}/")
42
+
43
+ end
44
+ rescue Exception => e
45
+ puts e
46
+ end
47
+
48
+ end
35
49
  end
36
- end
37
50
 
38
- flags = {
39
- :verbose => false,
40
- :debug => false,
41
- :directory => '/var/geomdtk/current/stage'
42
- }
43
- OptionParser.new do |opts|
44
- opts.banner = "
45
- Usage: #{__FILE__} [-v] file.shp.xml [file.shp.xml ...]
46
- #{__FILE__} [-v] metadata.xml [metadata.xml ...]
47
- #{__FILE__} [-v] [directory]
48
- "
49
- opts.on("-v", "--verbose", "Run verbosely") do |v|
50
- flags[:debug] = true if flags[:verbose]
51
- flags[:verbose] = true
52
- end
53
- end.parse!
54
- ARGV << flags[:directory] if ARGV.empty?
51
+ def run(args)
52
+ flags = {
53
+ :verbose => false,
54
+ :debug => false,
55
+ :rebuild => false,
56
+ :mv_jpg => true,
57
+ :directory => '/var/geomdtk/current/stage'
58
+ }
59
+ OptionParser.new do |opts|
60
+ opts.banner = "
61
+ Usage: #{__FILE__} [-v] file.shp.xml [file.shp.xml ...]
62
+ #{__FILE__} [-v] metadata.xml [metadata.xml ...]
63
+ #{__FILE__} [-v] [directory]
64
+ "
65
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
66
+ flags[:debug] = true if flags[:verbose]
67
+ flags[:verbose] = true
68
+ end
69
+ end.parse!(args)
70
+ args << flags[:directory] if args.empty?
55
71
 
56
- ap({:flags => flags, :argv => ARGV}) if flags[:debug]
72
+ ap({:flags => flags, :args => args}) if flags[:debug]
57
73
 
58
- n = 0
59
- ARGV.each do |fn|
60
- if File.directory? fn
61
- Dir.glob(File.join(fn, '**', '*.shp.xml')) do |fn2|
62
- process_file fn2, flags if File.exist?(fn2)
63
- n = n + 1
74
+ n = 0
75
+ args.each do |fn|
76
+ if File.directory? fn
77
+ Dir.glob(File.join(fn, '**', '*.shp.xml')) do |fn2|
78
+ process_file fn2, flags if File.exist?(fn2)
79
+ n = n + 1
80
+ end
81
+ Dir.glob(File.join(fn, '**', 'metadata.xml')) do |fn2|
82
+ process_file fn2, flags if File.exist?(fn2)
83
+ n = n + 1
84
+ end
85
+ elsif File.exist? fn
86
+ process_file fn, flags
87
+ n = n + 1
88
+ else
89
+ $stderr.puts "WARNING: Missing file <#{fn}>"
90
+ end
64
91
  end
65
- Dir.glob(File.join(fn, '**', 'metadata.xml')) do |fn2|
66
- process_file fn2, flags if File.exist?(fn2)
67
- n = n + 1
68
- end
69
- elsif File.exist? fn
70
- process_file fn, flags
71
- n = n + 1
72
- else
73
- $stderr.puts "WARNING: Missing file <#{fn}>"
92
+ puts "Processed #{n} ArcGIS metadata files"
74
93
  end
75
94
  end
76
- puts "Processed #{n} ArcGIS metadata files"
95
+
96
+ IngestArcGIS.new().run(ARGV)
77
97
 
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ require File.expand_path(File.dirname(__FILE__) + '/../config/boot')
4
+ require 'nokogiri'
5
+ require 'optparse'
6
+
7
+ class Iso2Geo < GeoHydra::Process
8
+ def main(flags)
9
+ isoXml = Nokogiri::XML(File.read(flags[:iso19139]))
10
+ if isoXml.nil? or isoXml.root.nil?
11
+ raise ArgumentError, "Empty ISO 19139"
12
+ end
13
+ if flags[:iso19110].nil?
14
+ fcXml = nil
15
+ else
16
+ fcXml = Nokogiri::XML(File.read(flags[:iso19110]))
17
+ end
18
+
19
+ ap({:isoXml => isoXml, :fcXml => fcXml, :flags => flags}) if flags[:debug]
20
+
21
+ # GeoMetadataDS
22
+ puts "Generating #{flags[:geoMetadata]}" if flags[:verbose]
23
+ xml = GeoHydra::Transform.to_geoMetadataDS(isoXml, fcXml, { 'purl' => flags[:purl] })
24
+ File.open(flags[:geoMetadata], 'wb') {|f| f << xml.to_xml(:indent => 2) }
25
+ end
26
+
27
+ def run(args)
28
+ flags = {
29
+ :debug => false,
30
+ :verbose => false
31
+ }
32
+
33
+ OptionParser.new do |opts|
34
+ opts.banner = <<EOM
35
+ Usage: #{File.basename(__FILE__)} [options]
36
+ EOM
37
+ opts.on('-v', '--verbose', 'Run verbosely') do |v|
38
+ flags[:debug] = true if flags[:verbose]
39
+ flags[:verbose] = true
40
+ end
41
+ opts.on('--purl URI', "PURL with druid") do |v|
42
+ flags[:purl] = v
43
+ end
44
+ %w{19110 19139}.each do |n|
45
+ opts.on("--iso#{n} FILE", "Input file with ISO #{n} XML") do |v|
46
+ flags["iso#{n}".to_sym] = v
47
+ end
48
+ end
49
+ opts.on('--geoMetadata FILE', "Output file with ISO 19139/19110 XML") do |v|
50
+ flags[:geoMetadata] = v
51
+ end
52
+ end.parse!(args)
53
+
54
+ %w{purl iso19139 geoMetadata}.each do |k|
55
+ raise ArgumentError, "Missing required --#{k} flag" if flags[k.to_sym].nil?
56
+ end
57
+
58
+ ap({:flags => flags}) if flags[:debug]
59
+ main flags
60
+ end
61
+ end
62
+
63
+ # __MAIN__
64
+ Iso2Geo.new().run(ARGV)
@@ -8,252 +8,146 @@ require 'optparse'
8
8
  require 'mods'
9
9
  require 'druid-tools'
10
10
  require 'dor-services'
11
-
12
- require 'active_record'
13
- require 'active_support'
14
11
  require 'tmpdir'
15
12
 
16
- class RegisteredLayer < ActiveRecord::Base
17
- attr_accessible :druid, :layername, :title
18
- # self.primary_key = 'druid'
19
-
20
- def find_by_druid(druid)
21
- RegisteredLayer.find(:first, :conditions => [ "druid = ?", druid.to_s])
22
- end
23
- end
24
-
13
+ class LoaderPostGIS < GeoHydra::Process
25
14
 
26
- # ENV['RGEOSERVER_CONFIG'] ||= ENV_FILE + '_rgeoserver.yml'
27
- # require 'rgeoserver'
15
+ # USAGE: shp2pgsql [<options>] <shapefile> [[<schema>.]<table>]
16
+ # OPTIONS:
17
+ # -s [<from>:]<srid> Set the SRID field. Defaults to 0.
18
+ # Optionally reprojects from given SRID (cannot be used with -D).
19
+ # (-d|a|c|p) These are mutually exclusive options:
20
+ # -d Drops the table, then recreates it and populates
21
+ # it with current shape file data.
22
+ # -a Appends shape file into current table, must be
23
+ # exactly the same table schema.
24
+ # -c Creates a new table and populates it, this is the
25
+ # default if you do not specify any options.
26
+ # -p Prepare mode, only creates the table.
27
+ # -g <geocolumn> Specify the name of the geometry/geography column
28
+ # (mostly useful in append mode).
29
+ # -D Use postgresql dump format (defaults to SQL insert statements).
30
+ # -e Execute each statement individually, do not use a transaction.
31
+ # Not compatible with -D.
32
+ # -G Use geography type (requires lon/lat data or -r to reproject).
33
+ # -k Keep postgresql identifiers case.
34
+ # -i Use int4 type for all integer dbf fields.
35
+ # -I Create a spatial index on the geocolumn.
36
+ # -S Generate simple geometries instead of MULTI geometries.
37
+ # -t <dimensionality> Force geometry to be one of '2D', '3DZ', '3DM', or '4D'
38
+ # -w Output WKT instead of WKB. Note that this can result in
39
+ # coordinate drift.
40
+ # -W <encoding> Specify the character encoding of Shape's
41
+ # attribute column. (default: "UTF-8")
42
+ # -N <policy> NULL geometries handling policy (insert*,skip,abort).
43
+ # -n Only import DBF file.
44
+ # -T <tablespace> Specify the tablespace for the new table.
45
+ # Note that indexes will still use the default tablespace unless the
46
+ # -X flag is also used.
47
+ # -X <tablespace> Specify the tablespace for the table's indexes.
48
+ # This applies to the primary key, and the spatial index if
49
+ # the -I flag is used.
50
+ # -? Display this help screen.
28
51
 
29
- #= Input data. *See DATA section at end of file*
30
- # The input file is in YAML syntax with each record is a Hash with keys:
31
- # - layername
32
- # - filename
33
- # - format
34
- # - title
35
- # and optionally
36
- # - description
37
- # - keywords
38
- # - metadata_links
52
+ def main layer, flags, format = :shapefile
53
+ druid = layer[:druid]
54
+ zipfn = layer[:zipfn]
55
+ projection = layer[:projection] || flags[:projection]
56
+ schema = layer[:schema] || flags[:schema]
57
+ encoding = layer[:encoding] || flags[:encoding]
58
+ ap({:druid => druid, :zipfn => zipfn, :projection => projection, :schema => schema, :encoding => encoding}) if flags[:debug]
39
59
 
40
- # USAGE: shp2pgsql [<options>] <shapefile> [[<schema>.]<table>]
41
- # OPTIONS:
42
- # -s [<from>:]<srid> Set the SRID field. Defaults to 0.
43
- # Optionally reprojects from given SRID (cannot be used with -D).
44
- # (-d|a|c|p) These are mutually exclusive options:
45
- # -d Drops the table, then recreates it and populates
46
- # it with current shape file data.
47
- # -a Appends shape file into current table, must be
48
- # exactly the same table schema.
49
- # -c Creates a new table and populates it, this is the
50
- # default if you do not specify any options.
51
- # -p Prepare mode, only creates the table.
52
- # -g <geocolumn> Specify the name of the geometry/geography column
53
- # (mostly useful in append mode).
54
- # -D Use postgresql dump format (defaults to SQL insert statements).
55
- # -e Execute each statement individually, do not use a transaction.
56
- # Not compatible with -D.
57
- # -G Use geography type (requires lon/lat data or -r to reproject).
58
- # -k Keep postgresql identifiers case.
59
- # -i Use int4 type for all integer dbf fields.
60
- # -I Create a spatial index on the geocolumn.
61
- # -S Generate simple geometries instead of MULTI geometries.
62
- # -t <dimensionality> Force geometry to be one of '2D', '3DZ', '3DM', or '4D'
63
- # -w Output WKT instead of WKB. Note that this can result in
64
- # coordinate drift.
65
- # -W <encoding> Specify the character encoding of Shape's
66
- # attribute column. (default: "UTF-8")
67
- # -N <policy> NULL geometries handling policy (insert*,skip,abort).
68
- # -n Only import DBF file.
69
- # -T <tablespace> Specify the tablespace for the new table.
70
- # Note that indexes will still use the default tablespace unless the
71
- # -X flag is also used.
72
- # -X <tablespace> Specify the tablespace for the table's indexes.
73
- # This applies to the primary key, and the spatial index if
74
- # the -I flag is used.
75
- # -? Display this help screen.
60
+ raise NotImplementedError, "Unsupported format: #{format}" unless format == :shapefile
76
61
 
77
- def main conn, layers, flags = {}
78
- ap({:layers => layers, :flags => flags}) if flags[:debug]
79
- layers.each do |k, v|
80
- %w{layername format filename title}.each do |i|
81
- raise ArgumentError, "Layer is missing required '#{i}'" if v[i.to_sym].nil? or not v.include?(i.to_sym)
82
- end
83
- puts "Processing layer #{k}" if flags[:verbose]
84
-
85
- layername = v[:layername].strip
86
- format = v[:format].downcase.strip.to_sym
87
- druid = v[:druid]
88
- title = v[:title].strip
89
-
90
- case format
91
- when :shapefile
92
- ap({:v => v}) if flags[:debug]
93
- Dir.mktmpdir('shp', druid.temp_dir) do |d|
94
- begin
95
- system("unzip -oj '#{v[:filename]}' -d '#{d}'")
96
- system("ls -la #{d}")
97
- Dir.glob("#{d}/*.shp") do |shp|
98
- # XXX: HARD CODED projection here -- extract from MODS or ISO19139
99
- # XXX: Perhaps put the .sql data into the content directory as .zip for derivative
100
- # XXX: -G for the geography column causes some issues with GeoServer
101
- system("shp2pgsql -d -D -I -W #{flags[:encoding]} '#{shp}' #{flags[:schema]}.#{druid.id} > '#{druid.temp_dir}/#{druid.id}.sql'")
102
- system('psql --no-psqlrc --no-password --quiet ' +
103
- "--host='#{flags[:host.to_s]}' " +
104
- "--port='#{flags[:port.to_s]}' " +
105
- "--username='#{flags[:username.to_s]}' " +
106
- "--dbname='#{flags[:database.to_s]}' " +
107
- "--file='#{druid.temp_dir}/#{druid.id}.sql' ")
108
- end
109
- rescue Exception => e
110
- FileUtils.rm_rf(d) if File.exist?(d)
62
+ Dir.mktmpdir('shp', druid.temp_dir) do |d|
63
+ begin
64
+ system("unzip -oj '#{zipfn}' -d '#{d}'")
65
+ system("ls -la #{d}") if flags[:debug]
66
+ Dir.glob("#{d}/*.shp") do |shp|
67
+ # XXX: HARD CODED projection here -- extract from MODS or ISO19139
68
+ # XXX: Perhaps put the .sql data into the content directory as .zip for derivative
69
+ # XXX: -G for the geography column causes some issues with GeoServer
70
+ system("shp2pgsql -s #{projection} -d -D -I -W #{encoding}" +
71
+ " '#{shp}' #{schema}.#{druid.id} " +
72
+ "> '#{druid.temp_dir}/#{druid.id}.sql'")
73
+ system('psql --no-psqlrc --no-password --quiet ' +
74
+ "--file='#{druid.temp_dir}/#{druid.id}.sql' ")
111
75
  end
76
+ rescue Exception => e
77
+ FileUtils.rm_rf(d) if File.exist?(d)
112
78
  end
113
-
114
- if flags[:register]
115
- puts "Registering layer #{druid.id}, #{layername}, #{title}" if flags[:verbose]
116
- layer = RegisteredLayer.find_by_druid druid.id
117
- ap({:found_layer => layer}) if flags[:debug]
118
- if layer.nil?
119
- layer = RegisteredLayer.new(
120
- :druid => druid.id,
121
- :layername => layername,
122
- :title => title
123
- )
124
- end
125
- layer.layername = layername
126
- layer.title = title
127
- ap({:updated_layer => layer}) if flags[:debug]
128
- layer.save
129
- end
130
- else
131
- raise NotImplementedError, "Unsupported format #{format}"
132
79
  end
133
80
  end
134
- end
135
81
 
136
- def from_druid druid, flags
137
- ap({:druid => druid}) if flags[:debug]
138
- prj = flags[:projection] || "EPSG:4326"
139
- prj = prj.split(':').join('_')
140
- druid = DruidTools::Druid.new(druid, flags[:datadir])
141
- mods_fn = druid.path('metadata/descMetadata.xml')
142
- puts "Loading #{mods_fn}" if flags[:verbose]
143
- mods = Mods::Record.new
144
- mods.from_url(mods_fn)
145
- ap({:mods => mods}) if flags[:debug]
82
+ # locates the data.zip file, preferring one with explicit projection
83
+ def druid2layer druid, flags
84
+ ap({:druid => druid}) if flags[:debug]
146
85
 
147
- geo_fn = druid.path('metadata/geoMetadata.xml')
148
- puts "Loading #{geo_fn}" if flags[:verbose]
149
- geo = Dor::GeoMetadataDS.from_xml(File.read(geo_fn))
150
- ap({:geo => geo}) if flags[:debug]
151
-
152
- zipfn = nil
153
- layername = nil
154
- projection = nil
155
- Dir.glob(druid.content_dir + "/*_#{prj}.zip") do |fn|
156
- puts "Found EPSG 4326 zip: #{fn}" if flags[:verbose]
157
- projection = '4326'
158
- zipfn = fn
159
- layername = File.basename(zipfn, "_#{prj}.zip")
160
- puts "Derived layername #{zipfn} -> #{layername}" if flags[:verbose]
161
- end
162
- if not zipfn
163
- Dir.glob(druid.content_dir + "/*.zip") do |fn|
164
- zipfn = fn
165
- layername = File.basename(zipfn, '.zip')
86
+ zipfn = nil
87
+ projection = nil
88
+ %w{4326}.each do |prj|
89
+ Dir.glob(File.join(druid.content_dir, "data_EPSG_#{prj}.zip")) do |fn|
90
+ puts "Found EPSG #{prj} zip: #{fn}" if flags[:verbose]
91
+ projection = prj
92
+ zipfn = fn
93
+ end
166
94
  end
167
- end
168
- raise ArgumentError, zipfn unless File.exist?(zipfn) and layername
169
- ap({:zipfn => zipfn, :layername => layername}) if flags[:debug]
170
- r = {
171
- :vector => {
95
+
96
+ if zipfn.nil?
97
+ Dir.glob(File.join(druid.content_dir, 'data.zip')) do |fn|
98
+ puts "Found native zip: #{fn}" if flags[:verbose]
99
+ zipfn = fn
100
+ projection = '4326' # XXX: Hardcoded assumption that native work is in WGS84 if missing derived work
101
+ end
102
+ end
103
+
104
+ raise ArgumentError, "Missing data ZIP file: #{zipfn}" unless File.exist?(zipfn)
105
+ raise ArgumentError, "Missing Projection" if projection.nil?
106
+ ap({:zipfn => zipfn}) if flags[:debug]
107
+
108
+ {
172
109
  :druid => druid,
173
- :format => 'Shapefile',
174
- :layername => layername,
175
- :filename => zipfn,
176
- :title => mods.full_titles.first,
177
- :projection => projection.nil?? '4326' : projection
110
+ :zipfn => zipfn,
111
+ :projection => projection
178
112
  }
179
- }
180
- r
181
- end
113
+ end
182
114
 
183
- # __MAIN__
184
- begin
185
- flags = {
186
- :debug => false,
187
- :verbose => false,
188
- :register => false,
189
- :register_drop => false,
190
- :register_table => 'registered_layers',
191
- :encoding => 'UTF-8',
192
- :datadir => '/var/geomdtk/current/workspace',
193
- :schema => GeoHydra::Config.postgis.schema || 'public'
194
- }
115
+ def run(args)
116
+ flags = {
117
+ :encoding => 'UTF-8',
118
+ :workspacedir => GeoHydra::Config.geohydra.workspace || 'workspace',
119
+ :schema => GeoHydra::Config.postgis.schema || 'druid'
120
+ }
121
+ args = %w{--help} if args.nil? or args.empty?
195
122
 
196
- OptionParser.new do |opts|
197
- opts.banner = "
198
- Usage: #{File.basename(__FILE__)} [-v] [druid ... | < druids]
199
- "
200
- opts.on("-v", "--verbose", "Run verbosely") do |v|
201
- flags[:debug] = true if flags[:verbose]
202
- flags[:verbose] = true
203
- end
204
- opts.on("-d DIR", "--datadir DIR", "Data directory on GeoServer (default: #{flags[:datadir]})") do |v|
205
- raise ArgumentError, "Invalid directory #{v}" unless File.directory?(v)
206
- flags[:datadir] = v
207
- end
208
- opts.on("-R", "--register", "Register shapefile") do |v|
209
- flags[:register] = true
210
- end
211
-
212
- %w{schema encoding}.each do |k|
213
- opts.on("--#{k} #{k.upcase}", "PostGIS #{k} (default: #{flags[k.to_sym]})") do |v|
214
- flags[k.to_sym] = v
123
+ OptionParser.new do |opts|
124
+ opts.banner = "Usage: #{File.basename(__FILE__)} [-v] druid [druid...]"
125
+ opts.on('-v', '--verbose', 'Run verbosely, use multiple times for debug level output') do
126
+ flags[:debug] = true if flags[:verbose] # -vv
127
+ flags[:verbose] = true
128
+ end
129
+ opts.on('--workspace DIR', "Workspace directory for assembly (default: #{flags[:workspacedir]})") do |v|
130
+ flags[:workspacedir] = v
215
131
  end
216
- end
217
- end.parse!
218
132
 
219
- ap({:flags => flags}) if flags[:debug]
220
- dbfn = File.expand_path(File.dirname(__FILE__) + '/../config/database.yml')
221
- puts "Loading #{dbfn}" if flags[:verbose]
222
- dbconfig = YAML.load(File.read(dbfn))
223
- raise ArgumentError, "Missing configuration for environment" unless dbconfig.include?(ENV['GEOHYDRA_ENVIRONMENT'])
224
- flags.merge! dbconfig[ENV['GEOHYDRA_ENVIRONMENT']]
225
- ap({:flags => flags}) if flags[:debug]
226
-
227
- ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new($stderr) if flags[:debug]
228
-
229
- conn = ActiveRecord::Base.establish_connection flags
230
- conn.with_connection do |db|
231
- # ap({:obj => db, :klass => db.class, :methods => db.public_methods, :schema_search_path => db.schema_search_path})
232
- puts "Connected to PostgreSQL #{db.select_value("SHOW server_version")} " +
233
- "using #{db.current_database} database" if flags[:verbose]
234
- if db.select_value('select default_version from pg_catalog.pg_available_extensions where name = \'postgis\'') =~ /^(2\.[\.\d]*)$/
235
- puts "Using PostGIS #{$1}" if flags[:verbose]
236
- else
237
- raise NotImplementedError, "Database does not have PostGIS support"
238
- end
239
- if flags[:register]
240
- n = db.select_value("SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' and tablename = '#{flags[:register_table]}'")
241
- if n.to_i == 0 or flags[:register_drop]
242
- puts "Creating registry table in public.#{flags[:register_table]}" if flags[:verbose]
243
- db.execute("DROP TABLE public.#{flags[:register_table]}") if flags[:register_drop]
244
- db.execute("
245
- CREATE TABLE public.#{flags[:register_table]}
246
- (
247
- druid character varying NOT NULL PRIMARY KEY,
248
- layername character varying NOT NULL,
249
- title character varying NOT NULL
250
- );
251
- ")
133
+ %w{schema encoding}.each do |k|
134
+ opts.on("--#{k} #{k.upcase}", "PostGIS flag #{k} (default: #{flags[k.to_sym]})") do |v|
135
+ flags[k.to_sym] = v
136
+ end
252
137
  end
253
- end
254
- end
138
+ end.parse!(args)
139
+
140
+ ap({:args => args, :flags => flags}) if flags[:debug]
255
141
 
256
- (ARGV.size > 0 ? ARGV : $stdin).each do |s|
257
- main(conn, from_druid(s.strip, flags), flags)
142
+ raise OptionParser::MissingArgument, "At least one druid required" if args.size == 0
143
+
144
+ args.each do |s|
145
+ druid = DruidTools::Druid.new(s.strip, flags[:workspacedir])
146
+ puts "Processing #{druid.id}" if flags[:verbose]
147
+ main(druid2layer(druid, flags), flags)
148
+ end
258
149
  end
259
- end
150
+ end
151
+
152
+ # __MAIN__
153
+ LoaderPostGIS.new.run(ARGV)