geo_concerns 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +101 -0
- data/.travis.yml +17 -0
- data/Gemfile +46 -0
- data/LICENSE +202 -0
- data/README.md +46 -0
- data/Rakefile +21 -0
- data/app/actors/geo_concerns/file_actor.rb +20 -0
- data/app/actors/geo_concerns/file_set_actor.rb +7 -0
- data/app/assets/images/geo_concerns/.keep +0 -0
- data/app/assets/images/geo_concerns/images/geocoder.png +0 -0
- data/app/assets/images/geo_concerns/images/throbber.gif +0 -0
- data/app/assets/images/geo_concerns/img/filter-icon.png +0 -0
- data/app/assets/images/geo_concerns/img/move-handle.png +0 -0
- data/app/assets/images/geo_concerns/img/resize-handle.png +0 -0
- data/app/assets/javascripts/geo_concerns/Control.Geocoder.js +1056 -0
- data/app/assets/javascripts/geo_concerns/application.js +5 -0
- data/app/assets/javascripts/geo_concerns/bounding_box_selector.js +100 -0
- data/app/assets/javascripts/geo_concerns/leaflet-boundingbox.js +467 -0
- data/app/assets/stylesheets/geo_concerns/Control.Geocoder.css +104 -0
- data/app/assets/stylesheets/geo_concerns/application.css +18 -0
- data/app/assets/stylesheets/geo_concerns/bounding_box.scss +7 -0
- data/app/assets/stylesheets/geo_concerns/leaflet-boundingbox.css +17 -0
- data/app/controllers/concerns/geo_concerns/file_sets_controller_behavior.rb +19 -0
- data/app/controllers/concerns/geo_concerns/image_works_controller_behavior.rb +13 -0
- data/app/controllers/concerns/geo_concerns/raster_works_controller_behavior.rb +23 -0
- data/app/controllers/concerns/geo_concerns/vector_works_controller_behavior.rb +23 -0
- data/app/forms/geo_concerns/basic_geo_metadata_form.rb +8 -0
- data/app/forms/geo_concerns/external_metadata_file_form.rb +8 -0
- data/app/forms/geo_concerns/georeferenced_form.rb +9 -0
- data/app/forms/geo_concerns/image_work_form.rb +9 -0
- data/app/forms/geo_concerns/raster_work_form.rb +8 -0
- data/app/forms/geo_concerns/vector_work_form.rb +8 -0
- data/app/helpers/bounding_box_helper.rb +24 -0
- data/app/helpers/geo_concerns/application_helper.rb +4 -0
- data/app/models/concerns/geo_concerns/basic_geo_metadata.rb +21 -0
- data/app/models/concerns/geo_concerns/external_metadata_file_behavior.rb +31 -0
- data/app/models/concerns/geo_concerns/extractors/fgdc_helper.rb +9 -0
- data/app/models/concerns/geo_concerns/extractors/fgdc_metadata_extractor.rb +114 -0
- data/app/models/concerns/geo_concerns/extractors/iso19139_helper.rb +50 -0
- data/app/models/concerns/geo_concerns/extractors/mods_helper.rb +15 -0
- data/app/models/concerns/geo_concerns/file_set/derivatives.rb +60 -0
- data/app/models/concerns/geo_concerns/file_set_presenter_behavior.rb +7 -0
- data/app/models/concerns/geo_concerns/geo_file_format_behavior.rb +37 -0
- data/app/models/concerns/geo_concerns/geo_file_set_behavior.rb +11 -0
- data/app/models/concerns/geo_concerns/georeferenced_behavior.rb +18 -0
- data/app/models/concerns/geo_concerns/image_file_behavior.rb +14 -0
- data/app/models/concerns/geo_concerns/image_work_behavior.rb +69 -0
- data/app/models/concerns/geo_concerns/metadata_extraction_helper.rb +28 -0
- data/app/models/concerns/geo_concerns/raster_file_behavior.rb +14 -0
- data/app/models/concerns/geo_concerns/raster_work_behavior.rb +82 -0
- data/app/models/concerns/geo_concerns/solr_document_behavior.rb +25 -0
- data/app/models/concerns/geo_concerns/vector_file_behavior.rb +14 -0
- data/app/models/concerns/geo_concerns/vector_work_behavior.rb +78 -0
- data/app/presenters/geo_concerns/geo_concerns_show_presenter.rb +30 -0
- data/app/presenters/geo_concerns/image_work_show_presenter.rb +18 -0
- data/app/presenters/geo_concerns/raster_work_show_presenter.rb +18 -0
- data/app/presenters/geo_concerns/vector_work_show_presenter.rb +10 -0
- data/app/processors/geo_concerns/processors/base_geo_processor.rb +86 -0
- data/app/processors/geo_concerns/processors/raster.rb +11 -0
- data/app/processors/geo_concerns/processors/raster/aig.rb +44 -0
- data/app/processors/geo_concerns/processors/raster/base.rb +74 -0
- data/app/processors/geo_concerns/processors/raster/dem.rb +46 -0
- data/app/processors/geo_concerns/processors/raster/processor.rb +27 -0
- data/app/processors/geo_concerns/processors/vector.rb +11 -0
- data/app/processors/geo_concerns/processors/vector/base.rb +68 -0
- data/app/processors/geo_concerns/processors/vector/processor.rb +25 -0
- data/app/processors/geo_concerns/processors/vector/shapefile.rb +20 -0
- data/app/processors/geo_concerns/processors/zip.rb +31 -0
- data/app/renderers/coverage_renderer.rb +34 -0
- data/app/runners/geo_concerns/runners/raster_derivatives.rb +9 -0
- data/app/runners/geo_concerns/runners/vector_derivatives.rb +9 -0
- data/app/schemas/geo_concerns/basic_geo_metadata_optional.rb +39 -0
- data/app/schemas/geo_concerns/basic_geo_metadata_required.rb +25 -0
- data/app/services/authority_service.rb +23 -0
- data/app/services/geo_concerns/derivative_path.rb +16 -0
- data/app/services/image_format_service.rb +4 -0
- data/app/services/metadata_format_service.rb +4 -0
- data/app/services/raster_format_service.rb +4 -0
- data/app/services/vector_format_service.rb +4 -0
- data/app/values/geo_concerns/coverage.rb +36 -0
- data/app/values/geo_concerns/time_period.rb +31 -0
- data/app/views/curation_concerns/file_sets/_form.html.erb +48 -0
- data/app/views/curation_concerns/image_works/_form.html.erb +23 -0
- data/app/views/curation_concerns/image_works/_image_work.html.erb +2 -0
- data/app/views/curation_concerns/image_works/_members.html.erb +30 -0
- data/app/views/curation_concerns/image_works/_related_image_files.html.erb +24 -0
- data/app/views/curation_concerns/image_works/_show_actions.html.erb +16 -0
- data/app/views/curation_concerns/image_works/show.html.erb +17 -0
- data/app/views/curation_concerns/raster_works/_form.html.erb +25 -0
- data/app/views/curation_concerns/raster_works/_members.html.erb +30 -0
- data/app/views/curation_concerns/raster_works/_raster_work.html.erb +2 -0
- data/app/views/curation_concerns/raster_works/_related_raster_files.html.erb +24 -0
- data/app/views/curation_concerns/raster_works/_show_actions.html.erb +16 -0
- data/app/views/curation_concerns/raster_works/show.html.erb +17 -0
- data/app/views/curation_concerns/vector_works/_form.html.erb +25 -0
- data/app/views/curation_concerns/vector_works/_related_vector_files.html.erb +24 -0
- data/app/views/curation_concerns/vector_works/_show_actions.html.erb +15 -0
- data/app/views/curation_concerns/vector_works/_vector_work.html.erb +2 -0
- data/app/views/curation_concerns/vector_works/show.html.erb +15 -0
- data/app/views/geo_concerns/_attribute_rows.html.erb +11 -0
- data/app/views/geo_concerns/_attributes.html.erb +13 -0
- data/app/views/geo_concerns/_form_additional_information.html.erb +11 -0
- data/app/views/geo_concerns/_form_bounding_box.html.erb +9 -0
- data/app/views/geo_concerns/_form_descriptive_fields.html.erb +9 -0
- data/app/views/geo_concerns/_form_files_and_links.html.erb +0 -0
- data/app/views/geo_concerns/_form_populate_metadata.html.erb +8 -0
- data/app/views/geo_concerns/_form_required_information.html.erb +12 -0
- data/app/views/geo_concerns/_form_supplementary_fields.html.erb +15 -0
- data/app/views/geo_concerns/_related_external_metadata_files.html.erb +24 -0
- data/app/vocabs/geo_concerns/geo_terms.rb +12 -0
- data/bin/rails +12 -0
- data/config/routes.rb +6 -0
- data/geo_concerns.gemspec +36 -0
- data/lib/generators/geo_concerns/install_generator.rb +119 -0
- data/lib/generators/geo_concerns/templates/actors/curation_concerns/image_work_actor.rb +4 -0
- data/lib/generators/geo_concerns/templates/actors/curation_concerns/raster_work_actor.rb +4 -0
- data/lib/generators/geo_concerns/templates/actors/curation_concerns/vector_work_actor.rb +4 -0
- data/lib/generators/geo_concerns/templates/config/authorities/image_formats.yml +5 -0
- data/lib/generators/geo_concerns/templates/config/authorities/metadata_formats.yml +7 -0
- data/lib/generators/geo_concerns/templates/config/authorities/raster_formats.yml +9 -0
- data/lib/generators/geo_concerns/templates/config/authorities/vector_formats.yml +5 -0
- data/lib/generators/geo_concerns/templates/controllers/curation_concerns/file_sets_controller.rb +6 -0
- data/lib/generators/geo_concerns/templates/controllers/curation_concerns/image_works_controller.rb +5 -0
- data/lib/generators/geo_concerns/templates/controllers/curation_concerns/raster_works_controller.rb +6 -0
- data/lib/generators/geo_concerns/templates/controllers/curation_concerns/vector_works_controller.rb +6 -0
- data/lib/generators/geo_concerns/templates/geo_concerns.js +1 -0
- data/lib/generators/geo_concerns/templates/geo_concerns.scss +3 -0
- data/lib/generators/geo_concerns/templates/jobs/characterize_job.rb +12 -0
- data/lib/generators/geo_concerns/templates/models/file_set.rb +4 -0
- data/lib/generators/geo_concerns/templates/models/image_work.rb +6 -0
- data/lib/generators/geo_concerns/templates/models/raster_work.rb +7 -0
- data/lib/generators/geo_concerns/templates/models/vector_work.rb +7 -0
- data/lib/generators/geo_concerns/templates/presenters/file_set_presenter.rb +3 -0
- data/lib/generators/geo_concerns/templates/spec/actor_spec.rb.erb +9 -0
- data/lib/generators/geo_concerns/templates/spec/controller_spec.rb.erb +9 -0
- data/lib/generators/geo_concerns/templates/spec/model_spec.rb.erb +9 -0
- data/lib/geo_concerns.rb +6 -0
- data/lib/geo_concerns/engine.rb +4 -0
- data/lib/geo_concerns/version.rb +3 -0
- data/lib/tasks/geo_concerns_tasks.rake +4 -0
- data/solr/config/_rest_managed.json +3 -0
- data/solr/config/admin-extra.html +31 -0
- data/solr/config/elevate.xml +36 -0
- data/solr/config/mapping-ISOLatin1Accent.txt +246 -0
- data/solr/config/protwords.txt +21 -0
- data/solr/config/schema.xml +372 -0
- data/solr/config/scripts.conf +24 -0
- data/solr/config/solrconfig.xml +312 -0
- data/solr/config/spellings.txt +2 -0
- data/solr/config/stopwords.txt +58 -0
- data/solr/config/stopwords_en.txt +58 -0
- data/solr/config/synonyms.txt +31 -0
- data/solr/config/xslt/example.xsl +132 -0
- data/solr/config/xslt/example_atom.xsl +67 -0
- data/solr/config/xslt/example_rss.xsl +66 -0
- data/solr/config/xslt/luke.xsl +337 -0
- data/spec/actors/geo_concerns/file_actor_spec.rb +26 -0
- data/spec/controllers/image_works_controller_spec.rb +25 -0
- data/spec/controllers/raster_works_controller_spec.rb +50 -0
- data/spec/controllers/vector_works_controller_spec.rb +50 -0
- data/spec/factories/external_metadata_files.rb +20 -0
- data/spec/factories/image_files.rb +32 -0
- data/spec/factories/image_works.rb +68 -0
- data/spec/factories/raster_files.rb +35 -0
- data/spec/factories/raster_works.rb +86 -0
- data/spec/factories/users.rb +26 -0
- data/spec/factories/vector_files.rb +31 -0
- data/spec/factories/vector_works.rb +83 -0
- data/spec/features/create_raster_work_spec.rb +49 -0
- data/spec/forms/geo_concerns/basic_geo_metadata_form_spec.rb +27 -0
- data/spec/forms/geo_concerns/external_metadata_file_form_spec.rb +27 -0
- data/spec/forms/geo_concerns/georeferenced_form_spec.rb +29 -0
- data/spec/forms/geo_concerns/image_work_form_spec.rb +11 -0
- data/spec/forms/geo_concerns/raster_work_form_spec.rb +15 -0
- data/spec/forms/geo_concerns/vector_work_form_spec.rb +15 -0
- data/spec/helpers/bounding_box_helper_spec.rb +34 -0
- data/spec/models/concerns/basic_geo_metadata_spec.rb +21 -0
- data/spec/models/concerns/geo_concerns/file_set/derivatives_spec.rb +108 -0
- data/spec/models/concerns/geo_concerns/file_set/geo_file_format_behavior_spec.rb +56 -0
- data/spec/models/external_metadata_file_spec.rb +118 -0
- data/spec/models/file_set_spec.rb +9 -0
- data/spec/models/image_file_spec.rb +48 -0
- data/spec/models/image_work_spec.rb +71 -0
- data/spec/models/raster_file_spec.rb +48 -0
- data/spec/models/raster_work_spec.rb +122 -0
- data/spec/models/solr_document_spec.rb +35 -0
- data/spec/models/vector_file_spec.rb +48 -0
- data/spec/models/vector_work_spec.rb +113 -0
- data/spec/presenters/file_set_presenter_spec.rb +13 -0
- data/spec/presenters/geo_concerns_show_presenter_spec.rb +56 -0
- data/spec/presenters/image_work_show_presenter_spec.rb +52 -0
- data/spec/presenters/raster_work_show_presenter_spec.rb +52 -0
- data/spec/presenters/vector_work_show_presenter_spec.rb +41 -0
- data/spec/processors/geo_concerns/processors/base_geo_processor_spec.rb +109 -0
- data/spec/processors/geo_concerns/processors/raster/aig_spec.rb +28 -0
- data/spec/processors/geo_concerns/processors/raster/base_spec.rb +86 -0
- data/spec/processors/geo_concerns/processors/raster/dem_spec.rb +26 -0
- data/spec/processors/geo_concerns/processors/raster/processor_spec.rb +39 -0
- data/spec/processors/geo_concerns/processors/vector/base_spec.rb +67 -0
- data/spec/processors/geo_concerns/processors/vector/processor_spec.rb +28 -0
- data/spec/processors/geo_concerns/processors/vector/shapefile_spec.rb +17 -0
- data/spec/processors/geo_concerns/processors/zip_spec.rb +39 -0
- data/spec/renderers/coverage_renderer_spec.rb +21 -0
- data/spec/services/derivative_path_spec.rb +12 -0
- data/spec/services/raster_format_service_spec.rb +13 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/controllers/engine_helpers.rb +7 -0
- data/spec/support/database_cleaner.rb +18 -0
- data/spec/support/devise.rb +10 -0
- data/spec/support/devise_helpers.rb +6 -0
- data/spec/support/factory_girl.rb +3 -0
- data/spec/support/features.rb +14 -0
- data/spec/support/features/session_helpers.rb +40 -0
- data/spec/support/fixture_reader.rb +7 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +20 -0
- data/spec/values/coverage_spec.rb +40 -0
- data/tasks/ci.rake +49 -0
- metadata +527 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
# Attributes and methods for vector files
|
3
|
+
module VectorFileBehavior
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include ::GeoConcerns::GeoreferencedBehavior
|
6
|
+
# Retrieve the Vector Work of which this Object is a member
|
7
|
+
# @return [GeoConcerns::VectorWork]
|
8
|
+
def vector_work
|
9
|
+
generic_works.select do |parent|
|
10
|
+
parent.class.included_modules.include?(::GeoConcerns::VectorWorkBehavior)
|
11
|
+
end.to_a
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
# Attributes and methods for vector works
|
3
|
+
module VectorWorkBehavior
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include ::GeoConcerns::MetadataExtractionHelper
|
6
|
+
|
7
|
+
included do
|
8
|
+
type [Hydra::PCDM::Vocab::PCDMTerms.Object,
|
9
|
+
Hydra::Works::Vocab::WorksTerms.GenericWork,
|
10
|
+
::GeoConcerns::GeoTerms.VectorWork]
|
11
|
+
end
|
12
|
+
|
13
|
+
def vector_files
|
14
|
+
members.select(&:vector_file?)
|
15
|
+
end
|
16
|
+
|
17
|
+
def metadata_files
|
18
|
+
members.select(&:external_metadata_file?)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Defines type by what it is and isn't
|
22
|
+
# @return [Boolean]
|
23
|
+
def image_work?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def image_file?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def raster_work?
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def raster_file?
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
def vector_work?
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def vector_file?
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def external_metadata_file?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
# Retrieve all Raster Works for which this Vector Work can be extracted
|
52
|
+
# @return [Array]
|
53
|
+
def raster_works
|
54
|
+
ordered_by.select do |parent|
|
55
|
+
parent.class.included_modules.include?(::GeoConcerns::RasterWorkBehavior)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Retrieve the only Raster Work for which feature extraction generates this Vector Work
|
60
|
+
# @return [GeoConcerns::RasterWork]
|
61
|
+
def raster_work
|
62
|
+
raster_works.first
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_solr(solr_doc = {})
|
66
|
+
super.tap do |doc|
|
67
|
+
doc[solr_name("ordered_by", :symbol)] ||= []
|
68
|
+
doc[solr_name("ordered_by", :symbol)] += send(:ordered_by_ids)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def solr_name(*args)
|
75
|
+
ActiveFedora.index_field_mapper.solr_name(*args)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
class GeoConcernsShowPresenter < CurationConcerns::WorkShowPresenter
|
3
|
+
delegate :has?, :first, to: :solr_document
|
4
|
+
delegate :spatial, :temporal, :issued, :coverage, :provenance, to: :solr_document
|
5
|
+
|
6
|
+
def members(presenter)
|
7
|
+
# TODO: member ids appear twice in member_ids_ssim.
|
8
|
+
# Figure out why instead of removing duplicates.
|
9
|
+
ids = solr_document.fetch('member_ids_ssim', [])
|
10
|
+
CurationConcerns::PresenterFactory.build_presenters(ids.uniq,
|
11
|
+
presenter,
|
12
|
+
current_ability)
|
13
|
+
end
|
14
|
+
|
15
|
+
def external_metadata_file_formats_presenters
|
16
|
+
# filter for external metadata files
|
17
|
+
members(::FileSetPresenter).select do |member|
|
18
|
+
MetadataFormatService.include? member.solr_document[:mime_type_ssi]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def attribute_to_html(field, options = {})
|
23
|
+
if field == :coverage
|
24
|
+
::CoverageRenderer.new(field, send(field), options).render
|
25
|
+
else
|
26
|
+
super field, options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
class ImageWorkShowPresenter < GeoConcernsShowPresenter
|
3
|
+
def raster_work_presenters
|
4
|
+
# filter for raster works
|
5
|
+
members(::GeoConcerns::RasterWorkShowPresenter).select do |member|
|
6
|
+
format = member.solr_document[:has_model_ssim]
|
7
|
+
format ? format.first == 'RasterWork' : false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def image_file_presenters
|
12
|
+
# filter for image files
|
13
|
+
members(::FileSetPresenter).select do |member|
|
14
|
+
ImageFormatService.include? member.solr_document[:mime_type_ssi]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
class RasterWorkShowPresenter < GeoConcernsShowPresenter
|
3
|
+
def vector_work_presenters
|
4
|
+
# filter for vector works
|
5
|
+
members(::GeoConcerns::VectorWorkShowPresenter).select do |member|
|
6
|
+
format = member.solr_document[:has_model_ssim]
|
7
|
+
format ? format.first == 'VectorWork' : false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def raster_file_presenters
|
12
|
+
# filter for raster files
|
13
|
+
members(::FileSetPresenter).select do |member|
|
14
|
+
RasterFormatService.include? member.solr_document[:mime_type_ssi]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
class VectorWorkShowPresenter < GeoConcernsShowPresenter
|
3
|
+
def vector_file_presenters
|
4
|
+
# filter for vector files
|
5
|
+
members(::FileSetPresenter).select do |member|
|
6
|
+
VectorFormatService.include? member.solr_document[:mime_type_ssi]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
module Processors
|
3
|
+
module BaseGeoProcessor
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
# Returns a formatted gdal_translate command. Used to translate a raster
|
8
|
+
# format into a different format. Also used in generating thumbnails
|
9
|
+
# from vector data.
|
10
|
+
#
|
11
|
+
# @param in_path [String] file input path
|
12
|
+
# #param options [Hash] creation options
|
13
|
+
# @param out_path [String] processor output file path
|
14
|
+
# @return [String] command for transforming a raster dataset
|
15
|
+
def self.translate(in_path, options, out_path)
|
16
|
+
"gdal_translate -outsize #{options[:output_size]} -q -ot Byte "\
|
17
|
+
"-of #{options[:output_format]} \"#{in_path}\" #{out_path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a path to an intermediate temp file.
|
21
|
+
#
|
22
|
+
# @param path [String] input file path to base temp path on
|
23
|
+
# @return [String] tempfile path
|
24
|
+
def self.intermediate_file_path(path)
|
25
|
+
ext = File.extname(path)
|
26
|
+
"#{File.dirname(path)}/#{File.basename(path, ext)}_temp#{ext}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def options_for(_format)
|
31
|
+
{
|
32
|
+
label: label,
|
33
|
+
output_format: output_format,
|
34
|
+
output_size: output_size,
|
35
|
+
output_srid: output_srid,
|
36
|
+
basename: basename
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the label directive or an empty string.
|
41
|
+
#
|
42
|
+
# @return [Sting] output label
|
43
|
+
def label
|
44
|
+
directives.fetch(:label, '')
|
45
|
+
end
|
46
|
+
|
47
|
+
# Tranforms the format directive into a GDAL output format.
|
48
|
+
#
|
49
|
+
# @return [Sting] derivative output format
|
50
|
+
def output_format
|
51
|
+
format = directives.fetch(:format, '').upcase
|
52
|
+
case format
|
53
|
+
when 'JPG'
|
54
|
+
'JPEG'
|
55
|
+
when 'TIF'
|
56
|
+
'GTiff'
|
57
|
+
else
|
58
|
+
format
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Tranforms the size directive into a GDAL size parameter.
|
63
|
+
#
|
64
|
+
# @return [String] derivative size
|
65
|
+
def output_size
|
66
|
+
return unless directives[:size]
|
67
|
+
directives[:size].tr('x', ' ')
|
68
|
+
end
|
69
|
+
|
70
|
+
# Gets srid for reprojection derivative or returns WGS 84.
|
71
|
+
#
|
72
|
+
# @return [String] spatial reference code
|
73
|
+
def output_srid
|
74
|
+
directives.fetch(:srid, 'EPSG:4326')
|
75
|
+
# directives[:srid] ? directives[:srid] : 'EPSG:4326'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Extracts the base file name (without extension) from the source file path.
|
79
|
+
#
|
80
|
+
# @return [String] base file name for source
|
81
|
+
def basename
|
82
|
+
File.basename(source_path, File.extname(source_path))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
module Processors
|
3
|
+
module Raster
|
4
|
+
class Aig < GeoConcerns::Processors::Raster::Base
|
5
|
+
include GeoConcerns::Processors::Zip
|
6
|
+
|
7
|
+
def self.encode(path, options, output_file)
|
8
|
+
unzip(path, output_file) do |zip_path|
|
9
|
+
info = gdalinfo(zip_path)
|
10
|
+
options[:min_max] = get_raster_min_max(info)
|
11
|
+
case options[:label]
|
12
|
+
when :thumbnail
|
13
|
+
encode_raster(zip_path, options, output_file)
|
14
|
+
when :display_raster
|
15
|
+
reproject_raster(zip_path, options, output_file)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.reproject_raster(in_path, options, out_path)
|
21
|
+
options[:output_size] = '100% 100%'
|
22
|
+
intermediate_file = intermediate_file_path(out_path)
|
23
|
+
execute warp(in_path, options, intermediate_file)
|
24
|
+
execute translate(intermediate_file, options, out_path)
|
25
|
+
FileUtils.rm_rf(intermediate_file)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a formatted gdal_translate command to translate a raster
|
29
|
+
# format into a different format with a scaling options. This command
|
30
|
+
# scales the min and max values of the raster into the 0 to 255 range.
|
31
|
+
# Scale is inverted (255 to 0) to create a better visualization.
|
32
|
+
#
|
33
|
+
# @param in_path [String] file input path
|
34
|
+
# #param options [Hash] creation options
|
35
|
+
# @param out_path [String] processor output file path
|
36
|
+
# @return [String] command for tranforming a usgs dem dataset
|
37
|
+
def self.translate(in_path, options, out_path)
|
38
|
+
"gdal_translate -scale #{options[:min_max]} 255 0 -outsize #{options[:output_size]} "\
|
39
|
+
"-q -ot Byte -of #{options[:output_format]} \"#{in_path}\" #{out_path}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
module Processors
|
3
|
+
module Raster
|
4
|
+
class Base < Hydra::Derivatives::Processors::Processor
|
5
|
+
include Hydra::Derivatives::Processors::ShellBasedProcessor
|
6
|
+
include GeoConcerns::Processors::BaseGeoProcessor
|
7
|
+
|
8
|
+
def self.encode(path, options, output_file)
|
9
|
+
case options[:label]
|
10
|
+
when :thumbnail
|
11
|
+
encode_raster(path, options, output_file)
|
12
|
+
when :display_raster
|
13
|
+
reproject_raster(path, options, output_file)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.encode_raster(in_path, options, out_path)
|
18
|
+
execute translate(in_path, options, out_path)
|
19
|
+
File.unlink("#{out_path}.aux.xml")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.reproject_raster(in_path, options, out_path)
|
23
|
+
intermediate_file = intermediate_file_path(out_path)
|
24
|
+
execute warp(in_path, options, intermediate_file)
|
25
|
+
execute compress(intermediate_file, options, out_path)
|
26
|
+
FileUtils.rm_rf(intermediate_file)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns a formatted gdalwarp. Used to transform a raster
|
30
|
+
# from one projection into another.
|
31
|
+
#
|
32
|
+
# @param in_path [String] file input path
|
33
|
+
# #param options [Hash] creation options
|
34
|
+
# @param out_path [String] processor output file path
|
35
|
+
# @return [String] command for reprojecting a raster
|
36
|
+
def self.warp(in_path, options, out_path)
|
37
|
+
"gdalwarp -q -r bilinear -t_srs #{options[:output_srid]} "\
|
38
|
+
" #{in_path} #{out_path} -co 'COMPRESS=NONE'"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns a formatted gdal_translate command. Used compress
|
42
|
+
# an previously uncompressed raster.
|
43
|
+
#
|
44
|
+
# @param in_path [String] file input path
|
45
|
+
# #param options [Hash] creation options
|
46
|
+
# @param out_path [String] processor output file path
|
47
|
+
# @return [String] command for compressing a raster dataset
|
48
|
+
def self.compress(in_path, options, out_path)
|
49
|
+
"gdal_translate -q -ot Byte -a_srs #{options[:output_srid]} "\
|
50
|
+
"\"#{in_path}\" #{out_path} -co 'COMPRESS=LZW'"
|
51
|
+
end
|
52
|
+
|
53
|
+
# Given an output string from the gdalinfo command, returns
|
54
|
+
# a formatted string for the computed min and max values.
|
55
|
+
#
|
56
|
+
# @param info_string [String] ouput from gdalinfo
|
57
|
+
# @return [String] computed min and max values
|
58
|
+
def self.get_raster_min_max(info_string)
|
59
|
+
match = %r{(?<=Computed Min/Max=).*?(?=\s)}.match(info_string)
|
60
|
+
match ? match[0].tr(',', ' ') : ''
|
61
|
+
end
|
62
|
+
|
63
|
+
# Runs the gdalinfo command and returns the result as a string.
|
64
|
+
#
|
65
|
+
# @param path [String] path to raster file
|
66
|
+
# @return [String] output of gdalinfo
|
67
|
+
def self.gdalinfo(path)
|
68
|
+
stdout, _stderr, _status = Open3.capture3("gdalinfo -mm #{path}")
|
69
|
+
stdout
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GeoConcerns
|
2
|
+
module Processors
|
3
|
+
module Raster
|
4
|
+
class Dem < GeoConcerns::Processors::Raster::Base
|
5
|
+
def self.encode_raster(in_path, options, out_path)
|
6
|
+
intermediate_file = intermediate_file_path(out_path)
|
7
|
+
execute translate(in_path, options, intermediate_file)
|
8
|
+
execute hillshade(intermediate_file, options, out_path)
|
9
|
+
FileUtils.rm_rf(intermediate_file)
|
10
|
+
File.unlink("#{out_path}.aux.xml")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.reproject_raster(in_path, options, out_path)
|
14
|
+
intermediate_file = intermediate_file_path(out_path)
|
15
|
+
execute hillshade(in_path, options, intermediate_file)
|
16
|
+
execute warp(intermediate_file, options, out_path)
|
17
|
+
FileUtils.rm_rf(intermediate_file)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a formatted gdal_translate command to translate a vector
|
21
|
+
# in USGS DEM format into a different format.
|
22
|
+
#
|
23
|
+
# @param in_path [String] file input path
|
24
|
+
# #param options [Hash] creation options
|
25
|
+
# @param out_path [String] processor output file path
|
26
|
+
# @return [String] command for tranforming a usgs dem dataset
|
27
|
+
def self.translate(in_path, options, out_path)
|
28
|
+
"gdal_translate -outsize #{options[:output_size]} -q -ot Byte "\
|
29
|
+
"-of USGSDEM #{in_path} #{out_path}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns a formatted gdal hillshade command. Calculates hillshade
|
33
|
+
# on a raster that contains elevation data.
|
34
|
+
#
|
35
|
+
# @param in_path [String] file input path
|
36
|
+
# #param options [Hash] creation options
|
37
|
+
# @param output_file [String] processor output file path
|
38
|
+
# @return [String] command for generating a hillshade
|
39
|
+
def self.hillshade(in_path, options, out_path)
|
40
|
+
"gdaldem hillshade -q "\
|
41
|
+
"-of #{options[:output_format]} \"#{in_path}\" #{out_path}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|