0

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.

butter_baby
  • 858
  • 2
  • 10
  • 24

1 Answers1

2

(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.

Community
  • 1
  • 1
vzsg
  • 2,831
  • 17
  • 20
  • Yeah, I read that online earlier. It looks like they're already converted EPSG:4326 in the example. I'm returning coordinates in my app that are in decimal degrees: 37.782683,-122.408917. How would I convert these using this tool? Thanks, btw. – butter_baby Feb 12 '17 at 10:11
  • In the tool, you have to select EPSG:4326 for input and EPSG:3857 for output; and you have to input the coordinates as `longitude;latitude`, so `-122.408917;37.782683` should work. – vzsg Feb 12 '17 at 10:17
  • Huh, it says it's out-of-range for some reason. Strange. – butter_baby Feb 12 '17 at 10:20
  • Strangely I input the example coords: -9663031.13, 3962292.03 and tried converting them to EPSG:4326 from EPSG:3857. It should have given me a point for Birmingham, AL but it said it didn't exist when I tried to plot it on the map using: http://www.latlong.net/ – butter_baby Feb 12 '17 at 10:27
  • You probably mixed up the longitude and the latitude when plotting it. I edited my answer to add some details about the conversion both with the tool and in code. – vzsg Feb 12 '17 at 10:34
  • Excellent answer, sir! Thank you so much for pointing me in the right direction. Sage advice! You saved me from a headache :D Cheers! – butter_baby Feb 12 '17 at 10:38