Convert plus code to GeoJSON Polygon

205 views
Skip to first unread message

Christian Sicari

unread,
Aug 10, 2020, 1:11:45 PM8/10/20
to Plus Codes Community Forum
I am using Plus code to code areas that I want to translate to geojson polygon in order to build GeoQuery on MongoDB.

I am converting plus code using the Node Library https://www.npmjs.com/package/open-location-code

I arrive to this resul
code=" 8FCQ5GXX+26"
decoded
=
{
  latitudeLo: 38.19750000000002,
  longitudeLo: 15.548000000000002,
  latitudeHi: 38.197625000000016,
  longitudeHi: 15.548124999999999,
  codeLength: 10,
  latitudeCenter: 38.19756250000002,
  longitudeCenter: 15.5480625
}



I work with which length varies from 10 digits to 14

Huroye Scott

unread,
Aug 10, 2020, 1:26:28 PM8/10/20
to Christian Sicari, Plus Codes Community Forum
Plus Code provides the coordinates, doesn’t it?

Roy

--
Public site: http://www.openlocationcode.com/
Github project: https://github.com/google/open-location-code
Demo site: http://plus.codes/
---
You received this message because you are subscribed to the Google Groups "Plus Codes Community Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-location-c...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/open-location-code/e2913acf-a266-4265-b479-c0d6486182aeo%40googlegroups.com.

Christian Sicari

unread,
Aug 11, 2020, 5:36:33 AM8/11/20
to Plus Codes Community Forum
I have center point and two angles of the rectangle.
I need the other two angles I think

Andreas B

unread,
Aug 11, 2020, 8:38:57 AM8/11/20
to Plus Codes Community Forum
OLC codes represent a four-sided area with its sides aligned with the lat/long grid (on the lat/long values "Lo" and "Hi").

After decoding a plus code as you already did, you should then be able to mix the "Lo" and "Hi" values to get the following four coordinates:
  1. latitudeLo / longitudeLo
  2. latitudeHi / longitudeLo
  3. latitudeHi / longitudeHi
  4. latitudeLo / longitudeHi
I don't know enough about GeJSON to tell you whether this order of coordinates is correct - if not, try the opposite order.

For what it's worth, there seems to be some floating point precision error going on with your result set. 10-digit codes should always have their borders on lat/long values that are an integer multiple of 0.000125°

Reply all
Reply to author
Forward
0 new messages