Skip to content

Commit

Permalink
Merge caf576a into f9e39ca
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurmolina committed May 24, 2015
2 parents f9e39ca + caf576a commit 059453c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions lib/geo_ruby/geojson.rb
Expand Up @@ -73,56 +73,56 @@ class GeoJSONParser
include GeoRuby::SimpleFeatures
attr_reader :geometry

def parse(geojson, srid = DEFAULT_SRID)
def parse(geojson, srid = DEFAULT_SRID, with_z = false, with_m = false)
@geometry = nil
geohash = JSON.parse(geojson)
parse_geohash(geohash, srid)
parse_geohash(geohash, srid, with_z, with_m)
end

private

def parse_geohash(geohash, srid)
def parse_geohash(geohash, srid, with_z, with_m)
srid = srid_from_crs(geohash['crs']) || srid
case geohash['type']
when 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon',
'MultiPolygon', 'GeometryCollection'
@geometry = parse_geometry(geohash, srid)
@geometry = parse_geometry(geohash, srid, with_z, with_m)
when 'Feature'
@geometry = parse_geojson_feature(geohash, srid)
@geometry = parse_geojson_feature(geohash, srid, with_z, with_m)
when 'FeatureCollection'
@geometry = parse_geojson_feature_collection(geohash, srid)
@geometry = parse_geojson_feature_collection(geohash, srid, with_z, with_m)
else
fail GeoJSONFormatError, 'Unknown GeoJSON type'
end
end

def parse_geometry(geohash, srid)
def parse_geometry(geohash, srid, with_z, with_m)
srid = srid_from_crs(geohash['crs']) || srid
if geohash['type'] == 'GeometryCollection'
parse_geometry_collection(geohash, srid)
parse_geometry_collection(geohash, srid, with_z, with_m)
else
klass = GeoRuby::SimpleFeatures.const_get(geohash['type'])
klass.from_coordinates(geohash['coordinates'], srid, false, false)
klass.from_coordinates(geohash['coordinates'], srid, with_z, with_m)
end
end

def parse_geometry_collection(geohash, srid)
def parse_geometry_collection(geohash, srid, with_z, with_m)
srid = srid_from_crs(geohash['crs']) || srid
geometries = geohash['geometries'].map { |g| parse_geometry(g, srid) }
GeometryCollection.from_geometries(geometries, srid)
geometries = geohash['geometries'].map { |g| parse_geometry(g, srid, with_z, with_m) }
GeometryCollection.from_geometries(geometries, srid, with_z, with_m)
end

def parse_geojson_feature(geohash, srid)
def parse_geojson_feature(geohash, srid, with_z, with_m)
srid = srid_from_crs(geohash['crs']) || srid
geometry = parse_geometry(geohash['geometry'], srid)
geometry = parse_geometry(geohash['geometry'], srid, with_z, with_m)
GeoJSONFeature.new(geometry, geohash['properties'], geohash['id'])
end

def parse_geojson_feature_collection(geohash, srid)
def parse_geojson_feature_collection(geohash, srid, with_z, with_m)
srid = srid_from_crs(geohash['crs']) || srid
features = []
geohash['features'].each do |feature|
features << parse_geojson_feature(feature, srid)
features << parse_geojson_feature(feature, srid, with_z, with_m)
end
GeoJSONFeatureCollection.new(features)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/geo_ruby/simple_features/geometry.rb
Expand Up @@ -233,9 +233,9 @@ def self.from_kml(kml)

# Some GeoJSON files do not include srid info, so
# we provide an optional parameter
def self.from_geojson(geojson, srid = DEFAULT_SRID)
def self.from_geojson(geojson, srid = DEFAULT_SRID, with_z = false, with_m = false)
geojson_parser = GeoJSONParser.new
geojson_parser.parse(geojson, srid)
geojson_parser.parse(geojson, srid, with_z, with_m)
geojson_parser.geometry
end

Expand Down

0 comments on commit 059453c

Please sign in to comment.