Fix MultiLineString geometries
This commit is contained in:
parent
50c0955465
commit
f71d2a608e
1 changed files with 19 additions and 0 deletions
|
@ -5,6 +5,7 @@ namespace :after_party do
|
||||||
|
|
||||||
geometry_collections = GeoArea.where("geometry -> 'type' = '\"GeometryCollection\"'")
|
geometry_collections = GeoArea.where("geometry -> 'type' = '\"GeometryCollection\"'")
|
||||||
multi_polygons = GeoArea.where("geometry -> 'type' = '\"MultiPolygon\"'")
|
multi_polygons = GeoArea.where("geometry -> 'type' = '\"MultiPolygon\"'")
|
||||||
|
multi_line_strings = GeoArea.where("geometry -> 'type' = '\"MultiLineString\"'")
|
||||||
|
|
||||||
def valid_geometry?(geometry)
|
def valid_geometry?(geometry)
|
||||||
RGeo::GeoJSON.decode(geometry.to_json, geo_factory: RGeo::Geographic.simple_mercator_factory)
|
RGeo::GeoJSON.decode(geometry.to_json, geo_factory: RGeo::Geographic.simple_mercator_factory)
|
||||||
|
@ -26,6 +27,24 @@ namespace :after_party do
|
||||||
end
|
end
|
||||||
progress.finish
|
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)
|
progress = ProgressReport.new(multi_polygons.count)
|
||||||
multi_polygons.find_each do |multi_polygon|
|
multi_polygons.find_each do |multi_polygon|
|
||||||
multi_polygon.geometry['coordinates'].each do |coordinates|
|
multi_polygon.geometry['coordinates'].each do |coordinates|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue