All Projects → geocrystal → geo

geocrystal / geo

Licence: MIT license
Geospatial primitives and algorithms for Crystal

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to geo

Z1p
Zip Codes Validation and Parse.
Stars: ✭ 17 (+0%)
Mutual labels:  geo, geolocation
Snoop
Snoop — инструмент разведки на основе открытых данных (OSINT world)
Stars: ✭ 886 (+5111.76%)
Mutual labels:  geo, geolocation
Flutter Geolocator
Android and iOS Geolocation plugin for Flutter
Stars: ✭ 759 (+4364.71%)
Mutual labels:  geo, geolocation
Places
🌐 Turn any <input> into an address autocomplete
Stars: ✭ 5,322 (+31205.88%)
Mutual labels:  geo, geolocation
React Native Android Location Services Dialog Box
React Native Android Location Services Dialog Box
Stars: ✭ 175 (+929.41%)
Mutual labels:  geo, geolocation
Geo On Fire
A library to create high performance geolocation queries for Firebase. Checkout the demos: https://run.plnkr.co/plunks/AYaN8ABEDcMntgbJyLVW/ and https://run.plnkr.co/plunks/xJgstAvXYcp0w7MbOOjm/
Stars: ✭ 54 (+217.65%)
Mutual labels:  geo, geolocation
Geo From Ip
Get geolocation 🌐 information about an IP 📲
Stars: ✭ 24 (+41.18%)
Mutual labels:  geo, geolocation
geocoder
Geocoder is a Typescript library which helps you build geo-aware applications by providing a powerful abstraction layer for geocoding manipulations
Stars: ✭ 28 (+64.71%)
Mutual labels:  geo, geolocation
haversine-geolocation
Get distances between two points or get closest position to current point. Based on the Haversine Formula
Stars: ✭ 20 (+17.65%)
Mutual labels:  geolocation, haversine
Geotools
Geo-related tools PHP 5.4+ library built atop Geocoder and React libraries
Stars: ✭ 1,157 (+6705.88%)
Mutual labels:  geo, geolocation
Clavin
CLAVIN (Cartographic Location And Vicinity INdexer) is an open source software package for document geoparsing and georesolution that employs context-based geographic entity resolution.
Stars: ✭ 237 (+1294.12%)
Mutual labels:  geo, geolocation
geodist
Golang package to compute the distance between two geographic latitude, longitude coordinates
Stars: ✭ 133 (+682.35%)
Mutual labels:  geolocation, haversine
addressr
Free Australian Address Validation, Search and Autocomplete
Stars: ✭ 46 (+170.59%)
Mutual labels:  geo
beihu-geo
地理位置解析服务,可供爬虫使用!供参考学习!
Stars: ✭ 16 (-5.88%)
Mutual labels:  geo
GoogleMap Demo
GoogleMap一些常用API总结库
Stars: ✭ 24 (+41.18%)
Mutual labels:  polygons
font-gis
Icon font and SVG for use with GIS and spatial analysis tools
Stars: ✭ 121 (+611.76%)
Mutual labels:  geo
openfairdb
Open Fair DB is the CreativCommons Backend of Kartevonmorgen.org
Stars: ✭ 53 (+211.76%)
Mutual labels:  geo
rgis
Performant, cross-platform (web, desktop) GIS app written in Rust
Stars: ✭ 79 (+364.71%)
Mutual labels:  geo
lala
🌎 Analyze and generate reports of web logs (NGINX)
Stars: ✭ 59 (+247.06%)
Mutual labels:  geolocation
world-cities-mongodb
A free world cities database
Stars: ✭ 29 (+70.59%)
Mutual labels:  geolocation

Geo

Crystal CI GitHub release Docs License

Geospatial primitives, algorithms, and utilities for Crystal.

Installation

Add this to your application's shard.yml:

dependencies:
  geo:
    github: geocrystal/geo

Run shards install

Usage

A Geo::Coord is a point in geographical coordinates: latitude and longitude.

require "geo"

c = Geo::Coord.new(50.004444, 36.231389)

c.strfcoord(%{%latd %latm' %0.1lats" %lath, %lngd %lngm' %0.1lngs" %lngh})
# => "50 0' 16.0" N, 36 13' 53.0" E"

c.strfcoord("%lat,%lng")
# => "-50.004444,-36.231389"

c.to_s
# => "50°0'16"N 36°13'53"E"

pos = Geo::Coord.new(50.004444, 36.231389)

pos.geohash
# => "ubcu2rnbuxcx"

pos.geohash(5)
# => "ubcu2"

Polygon

A polygon represents an area enclosed by a closed path (or loop), which is defined by a series of coordinates.

require "geo"

pos1 = Geo::Coord.new(45.3142533036254, -93.47527313511819)
pos2 = Geo::Coord.new(45.31232182518015, -93.34893036168069)
pos3 = Geo::Coord.new(45.23694281999268, -93.35167694371194)
pos4 = Geo::Coord.new(45.23500870841669, -93.47801971714944)

polygon = Geo::Polygon.new([pos1, pos2, pos3, pos4])

The Polygon in the example above consists of four sets of Geo::Coord coordinates, but notice that the first and last sets define the same location, which completes the loop. In practice, however, since polygons define closed areas, you don't need to specify the last set of coordinates. Ot will automatically complete the polygon by connecting the last location back to the first location.

The following example is identical to the previous one, except that the last Geo::Coord is omitted:

require "geo"

pos1 = Geo::Coord.new(45.3142533036254, -93.47527313511819)
pos2 = Geo::Coord.new(45.31232182518015, -93.34893036168069)
pos3 = Geo::Coord.new(45.23694281999268, -93.35167694371194)

polygon = Geo::Polygon.new([pos1, pos2, pos3])

Additional actions:

coord_inside = Geo::Coord.new(45.27428243796789, -93.41648483416066)
coord_outside = Geo::Coord.new(45.45411010558687, -93.78151703160256)

polygon.contains?(coord_inside)  # => true
polygon.contains?(coord_outside) # => false

polygon.centroid # => Geo::Coord(@lat=45.27463866133501, @lng=-93.41400121829719)

Additionally you can initialize polygon as convex hull from coordinates of points.

points = [
  {1.0, 1.0},
  {1.0, 0.0},
  {1.0, -1.0},
  {0.0, -1.0},
  {-1.0, -1.0},
  {-1.0, 0.0},
  {-1.0, 1.0},
  {0.0, 1.0},
  {0.0, 0.0},
].map { |point| Geo::Coord.new(point[0], point[1]) }

polygon = Geo::Polygon.new(points, convex_hull: true)
polygon.coords
# => {-1.0, -1.0}, {1.0, -1.0}, {1.0, 1.0}, {-1.0, 1.0}, {-1.0, -1.0}

The convex hull is computed using the convex_hull library.

Formatting

Geo::Coord#strfcoord formats coordinates according to directives.

Each directive starts with % and can contain some modifiers before its name.

Acceptable modifiers:

  • unsigned integers: none;
  • signed integers: + for mandatory sign printing;
  • floats: same as integers and number of digits modifier, like 0.3.

List of directives:

Directive Description
%lat Full latitude, floating point, signed
%latds Latitude degrees, integer, signed
%latd Latitude degrees, integer, unsigned
%latm Latitude minutes, integer, unsigned
%lats Latitude seconds, floating point, unsigned
%lath Latitude hemisphere, "N" or "S"
%lng Full longitude, floating point, signed
%lngds Longitude degrees, integer, signed
%lngd Longitude degrees, integer, unsigned
%lngm Longitude minutes, integer, unsigned
lngs Longitude seconds, floating point, unsigned
%lngh Longitude hemisphere, "E" or "W"

Examples:

g = Geo::Coord.new(50.004444, 36.231389)
g.strfcoord('%+lat, %+lng')
# => "+50.004444, +36.231389"
g.strfcoord("%latd°%latm'%lath -- %lngd°%lngm'%lngh")
# => "50°0'N -- 36°13'E"

strfcoord handles seconds rounding implicitly:

pos = Geo::Coord.new(0.033333, 91.333333)
pos.strfcoord('%latd %latm %0.5lats') # => "0 1 59.99880"
pos.strfcoord('%latd %latm %lats')  # => "0 2 0"

Calculate distances between two coords

Haversine formula from haversine shard is used.

require "geo"
require "geo/distance"

london = Geo::Coord.new(51.500153, -0.126236)
new_york = Geo::Coord.new(40.714268, -74.005974)

new_york.distance(london).to_kilometers
# => 5570.4744596620685

Contributing

  1. Fork it (https://github.com/geocrystal/geo/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].