butter_baby
butter_baby

Reputation: 888

Converting coordinates from decimal degrees to possibly EPSG 4326

I was given instructions for using an API and I'm having difficulty understanding how to convert the coordinates into the proper format. According to the API docs I am supposed to pass points or an array of polygon points:

To perform a point query, which finds the parcel which contains the given query point, make a request like the below: https://reportallusa.com/api/start_parcels_txn.php?client=xxxxx&si_srid=4326&spatial_intersect=[wkt_geometry] Where [wkt_geometry] is a url-encoded OGC Well-Known Text point or polygon geometry. The spatial reference system is WGS-84 lat/lon (EPSG 4326).

In the example, I'm given coordinates that have been converted to something different than Decimal Degrees:

For example, to perform a point query at the coordinate (-9663031.13, 3962292.03) which falls in the parcel at 1400 University Blvd, Birmingham, AL, form a point string: POINT(-9663031.13, 3962292.03) then urlencode it and pass as the "spatial_intersect" value: https://reportallusa.com/api/start_parcels_txn.php?client=xxxxx&spatial_intersect=POINT(-9663031.13%203962292.03) The response from the server is: {"status":"ok","parcel_count":1,"txn_id":"xxxxx"}

Now I've never seen coordinates in that type of format. I've looked at http://proj4.org/ for conversion tools or anything might be of use, but to no avail.

Does anyone have any idea what format these coordinates are in and if so, how can convert these in iOS? Thanks in advance.

Upvotes: 0

Views: 2962

Answers (1)

vzsg
vzsg

Reputation: 2896

(Disclaimer: I do not know this API, but I am certain that you should direct such questions to them. Nevertheless...)

If you visit the API root here, you'll find the following:

The spatial reference system is Spherical Mercator as used by Google and Bing: EPSG 3785 / 3857 / 900913.

Which is actually true! If you convert the example coordinates from EPSG:3857 to EPSG:4326, and take care to not reverse latitude and longitude, you'll see that the coordinates match up with the descriptions.

Just make sure that don't mix up longitude and latitude when looking up the results on a map.


To convert a WGS84 coordinate you get from iOS in the tool, you should:

  • select EPSG:4326 for input;
  • select EPSG:3857 for output;
  • and input coordinates as longitude;latitude (for example: -122.408917;37.782683).

To do this conversion programmatically, other SO questions will help. Porting any of those code fragments to Objective-C or Swift should be easy.

Upvotes: 2

Related Questions