Giter VIP home page Giter VIP logo

rgeo-geojson's Introduction

rgeo-geojson

Gem Version Build Status

rgeo-geojson is an extension to RGeo that provides GeoJSON encoding and decoding.

Summary

RGeo is a key component for writing location-aware applications in the Ruby programming language. At its core is an implementation of the industry standard OGC Simple Features Specification, which provides data representations of geometric objects such as points, lines, and polygons, along with a set of geometric analysis operations. See the README for the "rgeo" gem for more information.

RGeo::GeoJSON is an optional RGeo module that provides GeoJSON encoding and decoding. GeoJSON is a JSON format used for geographic data structures.

Example:

require 'rgeo/geo_json'

str1 = '{"type":"Point","coordinates":[1,2]}'
geom = RGeo::GeoJSON.decode(str1)
geom.as_text              # => "POINT (1.0 2.0)"

str2 = '{"type":"Feature","geometry":{"type":"Point","coordinates":[2.5,4.0]},"properties":{"color":"red"}}'
feature = RGeo::GeoJSON.decode(str2)
feature['color']          # => 'red'
feature.geometry.as_text  # => "POINT (2.5 4.0)"

hash = RGeo::GeoJSON.encode(feature)
hash.to_json == str2      # => true

Install

RGeo::GeoJSON requires:

  • Ruby 2.1.0 or later
  • rgeo 1.0.0 or later

Include in your bundle:

gem 'rgeo-geojson'

Install rgeo-geojson as a gem:

gem install rgeo-geojson

See the README for the rgeo gem, a required dependency, for further installation information.

Development and support

RDoc Documentation is available at http://rdoc.info/gems/rgeo-geojson

Source code is hosted on Github at https://github.com/rgeo/rgeo-geojson

Contributions are welcome. Fork the project on Github.

Report bugs on Github issues at http://github.com/rgeo/rgeo-geojson/issues

Acknowledgments

RGeo was created by Daniel Azuma (http://www.daniel-azuma.com).

Development is/was supported by Pirq and Neighborland.

License

Copyright (c) Daniel Azuma, Tee Parham

https://github.com/rgeo/rgeo-geojson/blob/master/LICENSE.txt

rgeo-geojson's People

Contributors

buonomo avatar calebwoods avatar dazuma avatar keithdoggett avatar quiwin avatar rgarner avatar teckwan avatar teeparham avatar tneems avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rgeo-geojson's Issues

No block given error in zm_feature_methods.rb

I'm generating GeoJSON from some UK Ordnance Survey data. I read in a .shp file, then create RGeo::GeoJSON::Feature objects from the geometries I get from the .shp file. This is mostly working, but some of my features fail when I try to do the GeoJSON encoding. The stacktrace is:

/home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:305:in `block in each': no block given (yield) (LocalJumpError)
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:304:in `times'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:304:in `each'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-0.5.2/lib/rgeo/geos/zm_feature_methods.rb:340:in `coordinates'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:183:in `_encode_geometry'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:130:in `_encode_feature'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:75:in `block in encode'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:141:in `each'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:141:in `each'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:195:in `map'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/entities.rb:195:in `map_feature_collection'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/coder.rb:75:in `encode'
    from /home/ian/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rgeo-geojson-0.4.1/lib/rgeo/geo_json/interface.rb:16:in `encode'
    from generate.rb:95:in `block in <main>'
    from generate.rb:94:in `open'
    from generate.rb:94:in `<main>'

Looking at the data I'm reading in, most of the geometries are CAPMultiPolygonImpl instances, but some of them are ZMultiPolygonImpl:

(byebug) features.take(10).map {|f| f.geometry.class}
[RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::CAPIMultiPolygonImpl, 
 RGeo::Geos::CAPIMultiPolygonImpl, RGeo::Geos::ZMMultiPolygonImpl]

The call to RGeo::GeoJSON.encode fails when it gets to the 10th element in that list. I'll keep digging, but I'm wondering first what is the reason that RGeo will encode some of the geometries as one class, and some another? What are the key differences between the CAPI- and ZM- polygons?

Bounding Box support?

When I try to encode the following well known text, I get a nil response.

RGeo::GeoJSON.encode("BBOX(-100 30,-120 30)")

Should I just convert this to a polygon or should bounding boxes be supported?

How to intersect two geojson files?

I am new to ruby and experimenting with rgeo.

I have 2 geojson files:
points.geojson contains a number of points
here is a gist of points.geojson:
https://gist.github.com/FergusDevelopmentLLC/2a4314be6d43ecda163979127d71caf5

outline.geojson contains a single polygon
here is a gist of my outline.geojson: https://gist.github.com/FergusDevelopmentLLC/1a7ae0708d7a8ee9e113f13654d39a4e

I want the intersection (points that are contained within outline)

Here is what I am trying...

require 'rgeo'
require 'rgeo/geo_json'

points_str = File.read("points.geojson")
points = RGeo::GeoJSON.decode(points_str, json_parser: :json)
puts points

outline_str = File.read("outline.geojson")
outline = RGeo::GeoJSON.decode(outline_str, json_parser: :json)
puts outline

puts points.intersection outline

The error I get:
intersection.rb:12:in <main>': undefined method intersection' for #RGeo::GeoJSON::FeatureCollection:0x294ac44 (NoMethodError)

the only thing I can find remotely similar is:
#34

decoder returns nil on valid GeoJson with duplicate point

If you got two exact same points in a polygon, then the parser returns nil. Is this my fault? Or is it a Bug in the parser?

I parse them with:
RGeo::GeoJSON.decode(geo_json_string, json_parser: :json)

returns nil:
{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[11.64,52.14],[11.65,52.15],[11.65,52.15],[11.63,52.17],[11.64,52.14]]]}}

returns RGeo::GeoJSON::Feature:
{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[11.64,52.14],[11.65,52.15],[11.65,52.16],[11.63,52.17],[11.64,52.14]]]}}

to_json is not producing json

require 'rgeo/geo_json'

def point(name, lat, lon)
    factory = RGeo::Cartesian.simple_factory(srid: 4326)
    point = factory.point(lat, lon)
    RGeo::GeoJSON::EntityFactory.instance.feature(point, {"name": name})
    return point
end

geometries = []
geometries << point("Null Island", 0, 0)
geometries << point("Marker of former Prime Meridiam", 51.4779959, -0.0014862)
puts(RGeo::GeoJSON::EntityFactory.instance.feature_collection(geometries).to_json)

gives

"#<RGeo::GeoJSON::FeatureCollection:0xf0>"

not an expected json

DatatypeMismatch with db queries using multipolygons

I'm fairly certain that I'm doing something wrong here but when using a the active-record rgeo gem and encoding a single polygon, I'm able to make a db query like this:

This works:
MyModel.where("latlon && ?", poly) where the latlon column is a point type and the poly represents a regular polygon that I generated from a linestring of coordinates using this factory: factory = RGeo::Geographic.spherical_factory(:srid => 4326)

This doesn't:
Using this gem, I encode a geojson multipolygon successfully using: poly = RGeo::GeoJSON.decode(mp.to_json, :json_parser => :json) Then I extract the geometry using:
poly = poly.geometry and that also seems to be successful. Now I try to run that same query from above:
MyModel.where("latlon && ?", poly) but this time it fails with this error:

PG::DatatypeMismatch at /api/v1/listings/polygon_search.json
============================================================

> ERROR:  argument of WHERE must be type boolean, not type record
LINE 1: SELECT "my_models".* FROM "my_model" WHERE (latlon && '002000...
            

How can I check element type?

Lets say that I have a geojson file and want to iterate over elements to ensure that only areas are there (no lines).

  geojson_text = File.open(input_geojson_file).read
  geom = RGeo::GeoJSON.decode(geojson_text)
  geom.each do |element|
    puts element
  end

how can I get type of a give element?

element.class gives RGeo::GeoJSON::Feature what is not useful

I see nothing relevant in https://rdoc.info/gems/rgeo-geojson/RGeo/GeoJSON/Feature

decode returns nil

RGeo::GeoJSON.decode returns nil for this geojson object:

{
  "type": "MultiPolygon",
  "coordinates": [
    [
      [
        [
          -0.1990879058837436,
          51.477187144041416
        ],
        [
          -0.2087009429931186,
          51.51160110043464
        ],
        [
          -0.1915348052978061,
          51.54342691492687
        ],
        [
          -0.15651588439941405,
          51.56071897849311
        ],
        [
          -0.05651588439941406,
          51.56071897849311
        ],
        [
          -0.019093704223678287,
          51.54769710912033
        ],
        [
          -0.0022708892822720372,
          51.50946436000716
        ],
        [
          -0.017720413208053287,
          51.478470108414456
        ],
        [
          -0.05651588439941406,
          51.46071897849311
        ],
        [
          -0.15651588439941405,
          51.46071897849311
        ],
        [
          -0.1990879058837436,
          51.477187144041416
        ]
      ],
      [
        [
          -0.07509474754328949,
          51.506753202923626
        ],
        [
          -0.07595305442805511,
          51.505273053858204
        ],
        [
          -0.06530280113224762,
          51.50174688870582
        ],
        [
          -0.05860800743107575,
          51.501608592703285
        ],
        [
          -0.047239065170288086,
          51.506897754163354
        ],
        [
          -0.04824938774106613,
          51.521613351060154
        ],
        [
          -0.06485271453857422,
          51.51832211713747
        ],
        [
          -0.07064137458792175,
          51.51599207347446
        ],
        [
          -0.07466559410090667,
          51.51464339775207
        ],
        [
          -0.07342104911799652,
          51.51155315619659
        ],
        [
          -0.07509474754328949,
          51.506753202923626
        ]
      ],
      [
        [
          -0.11228219406325,
          51.500309005889754
        ],
        [
          -0.12699723243713382,
          51.50865565022965
        ],
        [
          -0.12831687927246097,
          51.50922324175514
        ],
        [
          -0.12943267822265628,
          51.508421934016845
        ],
        [
          -0.12951850891113284,
          51.507620612185384
        ],
        [
          -0.12814521789550784,
          51.50708638980146
        ],
        [
          -0.11293737150024191,
          51.500256669057535
        ],
        [
          -0.1151615142822493,
          51.500079000259696
        ],
        [
          -0.12205123901367188,
          51.49633869308233
        ],
        [
          -0.12347106933589203,
          51.48981913832698
        ],
        [
          -0.11729125976557953,
          51.483370456473764
        ],
        [
          -0.10660171508789062,
          51.47968223294051
        ],
        [
          -0.09934539794926422,
          51.485615316067104
        ],
        [
          -0.09608383178715485,
          51.494664629895134
        ],
        [
          -0.10312194824223297,
          51.50104074392209
        ],
        [
          -0.11228219406325,
          51.500309005889754
        ]
      ],
      [
        [
          -0.1337242126464844,
          51.50893655316364
        ],
        [
          -0.12651443481445315,
          51.500174768121695
        ],
        [
          -0.11243820190429688,
          51.495686372106675
        ],
        [
          -0.10179519653320314,
          51.503594201752165
        ],
        [
          -0.12067794799804689,
          51.513637304278454
        ],
        [
          -0.1337242126464844,
          51.50893655316364
        ]
      ]
    ],
    [
      [
        [
          -0.1112794876098633,
          51.50120953016752
        ],
        [
          -0.11227726936340333,
          51.501015848029354
        ],
        [
          -0.1115691661834717,
          51.50054165725099
        ],
        [
          -0.1112794876098633,
          51.50120953016752
        ]
      ]
    ]
  ]
}

It was generated by leaflet and can be parsed by http://geojson.io/ and other tools.

Problem with decode and self-intersecting polygon

I have a valid GeoJSON polygon which I checked using the GeoJSON Lint service.

It is displayed perfectly in Google Maps, using the data.addGeoJson() method.

But when I try to decode it using

RGeo::GeoJSON.decode(polygon_json, :json_parser => :json)

I get a nil geometry. I have tried a lot of stuff but can get it to work correctly. Here's the GeoJSON polygon I'm trying to decode

{
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          -69.30999755859375,
          -33.610044573695632
        ],
        [
          -69.54620361328125,
          -33.89321737944087
        ],
        [
          -68.95294189453125,
          -33.749464192325767
        ],
        [
          -69.1094970703125,
          -33.982086259019368
        ],
        [
          -69.30999755859375,
          -33.610044573695632
        ]
      ]
    ]
  },
  "type": "Feature",
  "properties": {
    "Campo 1 (Texto)": null,
    "gx_id": "undefined-undefined-1422304622752",
    "Campo 3 (Num\u00e9rico)": null,
    "Campo 2 (Texto)": null
  }
}

The problem is not specific to this polygon, it happens with any polygon which has lines that go over previous lines in the polygon, like this

geojson lint example

The geoJSON representation of the polygons are created by me in JS based on user input from Google Maps Draw Tools.

Is there something wrong with my polygon coordinates? Is there anything I can do to fix this issue or is it an issue of the gem?

Thank you for reading

Feature.property(:foo) doesn't work

When creating RGeo::GeoJSON::Feature objects with properties, you (naturally) have two ways to describe the properties hash, with the keys being either strings or symbols. For example

f1 = RGeo::GeoJSON::Feature.new(geom, id, {:foo => "bar"})
f2 = RGeo::GeoJSON::Feature.new(geom, id, {"foo" => "bar"})

Either way, you end up with the same geojson output. However, feature.property(key) doesn't work for the symbol approach

> f1.property(:foo)
 => nil 
> f2.property("foo")
 => "bar" 

It's not clear to me why .to_s is called on the key at https://github.com/dazuma/rgeo-geojson/blob/master/lib/rgeo/geo_json/entities.rb#L123 , but this is what's causing the bug. Perhaps it can be removed?

Encoding nil

Current behavior:

1.9.3-p125 :001 > RGeo::GeoJSON.encode(nil)
NoMethodError: undefined method `factory' for nil:NilClass
    from /..../gems/activesupport-3.0.12/lib/active_support/whiny_nil.rb:48:in `method_missing'

Would it be acceptable to simply return nil here? Otherwise it forces developers to include a condition when encoding, for example, arbitrary ActiveRecord object attributes, in which some of them may be nil.

Decode empty FeatureCollection should not return nil

Decoding an empty FeatureCollection returns nil:

RGeo::GeoJSON.decode('{"features": [], "type": "FeatureCollection"}{"features": [], "type": "FeatureCollection"}',  json_parser: :json)
=> nil

I would think it should return an empty RGeo::GeoJSON::FeatureCollection instead, like so:

feats = RGeo::GeoJSON.decode('{"features": [], "type": "FeatureCollection"}{"features": [], "type": "FeatureCollection"}',  json_parser: :json)
=> #<RGeo::GeoJSON::FeatureCollection:0x3465520>
feats.count
=> 0

Minor error in entities.rb: misspelling of object_id

In lib/rgeo/geo_json/entities.rb, lines 26ff

def inspect # :nodoc:
    "#<#{self.class}:0x#{objectid.to_s(16)} id=#{@id.inspect} geom=#{@geometry ? @geometry.as_text.inspect : 'nil'}>"
end

objectid.to_s should read object_id.to_s

Decoder discards additional co-ordinates

Given the Point:

{
    "type": "Point",
    "coordinates": [102.0, 0.0, 0.0, "2011-03-29T08:38:50Z", 3.54, 39.80]
}

Where indices 0, 1, and 2 represent x, y and z co-ordinates and indices 3, 4 and 5 represent custom metadata about a point (in this case, timestamp, speed and bearing), rgeo-geojson discards the additional elements of the co-ordinates array. This is not expected behaviour.

According to the GeoJSON spec, additional elements are perfectly acceptable (emphasis mine):

A position is represented by an array of numbers. There must be at least two elements, and may be more. The order of elements must follow x, y, z order (easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). Any number of additional elements are allowed -- interpretation and meaning of additional elements is beyond the scope of this specification.

encode lat/long ordering

I defined my polygon using RGeo::Geographic.simple_mercator_factory

factory = RGeo::Geographic.simple_mercator_factory

bronowice = factory.point(50.078936, 19.877016)
bienczyce = factory.point(50.083266, 20.029741)
debniki = factory.point(50.011346, 19.869917)
biezanow = factory.point(50.011099, 20.035068)
line = factory.line_string([bronowice, bienczyce, biezanow, debniki])
area = factory.polygon(line)

When I tried to encode polygon I get wrong order of long/lat ( geoJson should reverse lat/long )and also it is unnnecessary nested array in :coordinates

{"type"=>"Polygon", "coordinates"=>[[[50.078936, 19.877016], [50.083266, 20.029741], [50.011099, 20.035068], [50.011346, 19.869917], [50.078936, 19.877016]]]}

I would like to add a more detailed example / getting started guide

I would like to use this gem but am having trouble finding information on how to use it. I've read the README for this and rgeo, and most of the documentation for this gem. I've also started looking through the source code and have some questions.

If you're open to it, I'd like to add a getting started wiki. I can get a PR together but would need a little help. Here are some of my questions:

  1. When I'm creating an EntityFactory or Feature, what type of object do I need to pass in as the geometry object (first argument)? I see that Coder#_encode_geometry checks to see if it is one of many RGeo::Feature objects, but when I looked at RGeo::Feature::Point I realized that it was a module, not an object. Does the geometry object just need to respond to interface laid out in RGeo::Feature::Point? And maybe coordinates too, since Coder#_encode_geometry will call that method?
  2. What is the purpose / use case for EntityFactory? To me, it doesn't seem any easier to use EntityFactory to build a feature than it is to just use the feature class itself (i.e. Feature.new(...)). Is it maybe supposed to serve as a base class for your own customized factories?
  3. Can RGeo::GeoJSON.encode accept both EntityFactory and Feature/FeatureCollection objects?

I can play around with things in a pry console and try to answer some of my own questions, but I thought it would be helpful to document these here and keep them in mind when writing a getting started guide.

It might also be helpful for me to look at the source code of an application that is using this gem. I found a list of projects that are using the gem (I think it was in an issue somewhere), but it was too hard to find the corresponding source code repos (maybe they're private). Do you have a recommendation for a repo to look at?

Polygons and MultiPolygons should follow the right-hand rule

Since GeoJSON is now a formal specification https://tools.ietf.org/html/rfc7946#section-3.1.6 I believe that RGeo::GeoJSON.encode should return a valid GeoJSON result.

One thing is to detect if polygons are right-hand wound (I guess Ruby Vector[].cross_product() method from the matrix module could do, some inspirations: https://github.com/mapbox/geojsonhint/blob/master/lib/rhr.js).

Second thing is to properly rewind the polygons (this JS package does the job: https://github.com/mapbox/geojson-rewind).

Let me know if this issue was already discussed or if someone already has a solution for this problem.

Monkey patch core with `to_geojson`

As part of our RGeo core v3 roadmap, we would like easier geojson usage. Here's one of the steps to go in that direction.

The goal is to provide the next functions to all factories:

  • to_geojson / to_json giving a String geojson
  • as_geojson / as_json giving a Hash geojson
  • Factory#parse_geojson (similar to Factory#parse_wkt)

To be included in all factories, the easiest is to add the new module to RGeo::Feature::Instance which is in every factories.

Attention points:

  • Use MultiJson
  • Be perf aware
  • make sure to test all factories
  • write related rdoc

How to add properties to a Feature

How can I add more items to a Feature property Hash?
Using merge! does not seem to work

irb(main):001:0> ff = RGeo::GeoJSON.decode(Scenario.find(11).polygon)
=> #<RGeo::GeoJSON::FeatureCollection:0x724c>

irb(main):002:0> ff[0].properties
=> {"myType"=>"base_area"}

irb(main):005:0> ff[0].properties.merge!("k"=>"22")
=> {"myType"=>"base_area", "k"=>"22"}

irb(main):006:0> ff[0].properties
=> {"myType"=>"base_area"}

Which works in a 'normal' Hash

nn = Hash.new
=> {}

irb(main):041:0> nn.merge!("k"=>"22")
=> {"k"=>"22"}

irb(main):042:0> nn
=> {"k"=>"22"}

Always encapsulate geometries within features

Always consider a geometry either as a feature or feature collection. This will help us keeping something identical when serializing/deserializing. And always having the same interface to handle a geometry (always working with RGeo::GeoJSON::Feature)

Long Time to Decode GeoJson MultiPolygons with lots of coordinates

I've run into an issue with decoding multipolygons that contain a really large number of coordinates. I noticed it on one in particular that contained a little over 10k points and it was taking 38 seconds on Heroku. (And the heroku router times out at 30 sec...)

Is there anything I can do to speed things along? The polygons are are cartesian (not 3d) and used to later query for rgeo points that st_intersects (if we could get past this decoding part)

The polygon in question can be found and tested here

I'm using this code to decode it: poly = RGeo::GeoJSON.decode(mp.to_json, :json_parser => :json)
(mp is the geojson multipolygon in the linked gist) and this seems to work without issue for other polygons with fewer points.

Any and all tips are greatly appreciated!

How to determine if a latitude, longitude fall within a feature (polygon) of a geojson feature collection?

I have been through the documentation and wasn't able to find anything on checking to see if a [lat, long] point falls within a feature of a geojson feature collection. Mapbox / leaflet have a getBounds([lat, long]) function that can be run on a geojson feature object to determine whether the point falls within the shape. I was wondering if there is anything similar available in rgeo-geojson, if not what would be the best way for me to go about writing such a function.
Thanks.

Encode PostGIS compatible Polygon

Thanks for the great lib. For the most part it has been a breeze to use. I am however coming across a bit of an issue when attempting to encode a Geometry value to geoJson.

'POLYGON ((-73.79113930812991 42.208615924064496, -73.79113930812991 42.20864290367541, -73.79110288382999 42.20864290367541, -73.79110288382999 42.208615924064496, -73.79113930812991 42.208615924064496))'

When attempting to encode the value above using RGeo::GeoJSON.encode I get nil

Any help would be greatly appreciated!

No Lib folder

I installed the gem but I do not have a lib/rgeo/... folder. Is this normal? Do I have to create this folder manually?

Error when I add a geo_factory

I'm trying to parse a Geojson file but I get the following error when I add a geo_factory:
RGeo::Error::InvalidGeometry: LinearRing failed ring test

This is the code I used

@geo_factory = RGeo::Geographic.spherical_factory(srid: 4326)
governorates = RGeo::GeoJSON.decode(File.open('./stanford-bb409wq6265-geojson.json').read, geo_factory: @geo_factory)

Is there's a way around this issue?

Fail to decode polygons with overlapping areas

I've noticed a problem when trying to decode areas with "bowtie" like shapes:

geojson = '{"type":"Polygon","coordinates":[[[40.1605224609375,50.48547354578499],[41.890869140625,49.75642885858046],[41.8963623046875,50.447011182312195],[40.1495361328125,50.025387620270244],[40.1605224609375,50.48547354578499]]]}'
polygon = RGeo::GeoJSON.decode(geojson, json_parser: :json)
# => returns nil

And, as you can see here, this is a valid Geo JSON Polygon.

Debugging the code, we could check that lib/rgeo/geo_json/coder.rb @ line 246 calls

ring = @geo_factory.linear_ring(points)

Which actually raises an RGeo::Error::InvalidGeometry: LinearRing failed ring test and returns nil.

Version tested: 0.4.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.