Fix MultiLineString geometries

This commit is contained in:
Paul Chavard 2020-09-20 13:18:53 +02:00
parent 50c0955465
commit f71d2a608e

View file

@ -5,6 +5,7 @@ namespace :after_party do
geometry_collections = GeoArea.where("geometry -> 'type' = '\"GeometryCollection\"'")
multi_polygons = GeoArea.where("geometry -> 'type' = '\"MultiPolygon\"'")
multi_line_strings = GeoArea.where("geometry -> 'type' = '\"MultiLineString\"'")
def valid_geometry?(geometry)
RGeo::GeoJSON.decode(geometry.to_json, geo_factory: RGeo::Geographic.simple_mercator_factory)
@ -26,6 +27,24 @@ namespace :after_party do
end
progress.finish
progress = ProgressReport.new(multi_line_strings.count)
multi_line_strings.find_each do |multi_line_string|
multi_line_string.geometry['coordinates'].each do |coordinates|
geometry = {
type: 'LineString',
coordinates: coordinates
}
if valid_geometry?(geometry)
multi_line_string.champ.geo_areas.create!(geometry: geometry, source: 'selection_utilisateur')
end
end
multi_line_string.destroy
progress.inc
end
progress.finish
progress = ProgressReport.new(multi_polygons.count)
multi_polygons.find_each do |multi_polygon|
multi_polygon.geometry['coordinates'].each do |coordinates|