@@ -612,6 +612,8 @@ def mask!
612612 else
613613 return "no masking file matching specified format found."
614614 end
615+
616+ self . mask_geojson = convert_mask_to_geojson
615617
616618 masked_src_filename = self . masked_src_filename
617619 if File . exists? ( masked_src_filename )
@@ -668,6 +670,8 @@ def warp!(resample_option, transform_option, use_mask="false")
668670 if use_mask == "true" && self . mask_status == :masked
669671 src_filename = self . masked_src_filename
670672 mask_options = " -srcnodata '17 17 17' "
673+
674+ self . mask_geojson = convert_mask_to_geojson if self . mask_geojson . blank?
671675 else
672676 src_filename = self . unwarped_filename
673677 end
@@ -966,6 +970,32 @@ def clear_cache
966970 Rails . cache . delete_matched ".*/maps/wms/#{ self . id } .png\? status=warped.*"
967971 Rails . cache . delete_matched "*/maps/tile/#{ self . id } /*"
968972 end
973+
974+ #takes in the clipping mask file, transforms it to geo and converts to geojson, returning the geojson
975+ def convert_mask_to_geojson
976+ if self . gcps . hard . size < 3
977+ return nil ;
978+ else
979+ gcp_array = self . gcps . hard
980+ gcp_string = ""
981+ gcp_array . each do |gcp |
982+ gcp_string = gcp_string + gcp . gdal_string
983+ end
984+
985+ command = "ogr2ogr -f 'geojson' -s_srs 'epsg:4326' -t_srs 'epsg:3857' #{ gcp_string } /dev/stdout #{ self . masking_file_gml } "
986+ logger . info command
987+ o_out , o_err = Open3 . capture3 ( command )
988+
989+ if !o_err . blank?
990+ logger . error "Error ogr2ogr script" + o_err
991+ logger . error "output = " +o_out
992+ return nil ;
993+ end
994+
995+
996+ return o_out
997+ end
998+ end
969999
9701000
9711001end
0 commit comments