This is a sample script that uses basic features of rgeo
and rgeo-geojson
.
It does two things:
- calculates the distance between the centroids of Berkeley, CA and Oakland, CA
- calculates the intersection of the neighborhoods Potrero and Mission District
To run:
$ bundle install
$ ruby script.rb
Output:
Distance from Berkeley centroid to Oakland centroid: 7.848 miles
Intersection of the neighboorhoods Potrero and Mision District as GeoJSON:
{"type":"Polygon","coordinates":[[[-122.40787994442341,37.76893943579835],[-122.407768,37.767803],[-122.407627,37.766277],[-122.407578,37.765787],[-122.407413,37.764128],[-122.407257,37.76254],[-122.407107,37.760945],[-122.406944,37.759136],[-122.406762,37.757299],[-122.406652,37.756017],[-122.406481,37.754445],[-122.406345,37.752933],[-122.406191,37.751398],[-122.4061358,37.7509507],[-122.406061,37.75077],[-122.405842,37.750335],[-122.405541,37.749776],[-122.405453,37.749611],[-122.405361,37.749476],[-122.40513675477644,37.74923953628669],[-122.405148,37.7492419800001],[-122.40551088,37.7494849800001],[-122.40564012,37.749546],[-122.40584316,37.7495980200001],[-122.40611208,37.7496389700001],[-122.40690912,37.74968496],[-122.40882504,37.7495769600001],[-122.40915084,37.7530059600002],[-122.40925992,37.7544230100002],[-122.409351,37.7549569800001],[-122.40941508,37.7554920300001],[-122.40951192,37.7566020000002],[-122.40954396,37.7574740100002],[-122.40970416,37.758906],[-122.40974196,37.7590930200002],[-122.40985212,37.7593499700001],[-122.40989388,37.7595019800001],[-122.41044396,37.7651439900001],[-122.41082916,37.7693690400001],[-122.40888192,37.76905701],[-122.40830304,37.7689779900001],[-122.40787994442341,37.76893943579835]]]}