I am building a non mapping javascript app and I am wanting to take a lat/long coordinate and query a MySQL table of polygons for the one that contains the point.

I have looked into MySQL spatial datatypes and how to query it, however, it seems to me that you can only return a true/false value for whether or not a specific point is within a specific polygon. What I want to do is look in a massive table for the correct polygon. My goal is to find the polygon.

I have also looked into maybe using PostgreSQL and PostGIS, but haven't found a solution yet.

Can anyone here point me in the right direction?

closed as primarily opinion-based by Mapperz Oct 10 '13 at 2:14

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to gis.SE. In SQL, are you just going to be looking for SELECT polygon_id WHERE ST_Within({point},geom_col)? If not, you'll have to provide more details such as the sql schema you are using, and some sample data. If all you are looking for is points, then you should be able to use RTree in any common database (SqlLite, mysql, sqlserver, postgres with or without postgis). – BradHards Oct 10 '13 at 1:50
  • ESRI (ArcSDE) is only a 'gateway' to the DBMS. The question as it stands is going recieve answers that will be opinion/experienced based. – Mapperz Oct 10 '13 at 2:16
  • Brad, I think so, yes. My app will essentially take a zip code centroid point (lat/long) in decimal degrees. Then take that point and get rainfall data from the polygon that the point is within. To me, this query makes sense: SELECT polygon_id, polygon_rainfall FROM polygon_table WHERE ST_CONTAINS({point_coords}, polygon_geom_column); Is this correct? – ezekielweb Oct 10 '13 at 14:45

ESRI doesn't make a DBMS, they make middleware...

But on databases, you should almost certainly use PostGres (PostGIS).

This is the operation you want: ST_Contains. I think PHP is the easiest language to use for this, but get the query working in PGAdmin, then do it in your server side scripting language. Or whatever!

  • My server is WHM / cPanel... is PostGIS something I can install myself? How does one go about doing that? Or maybe the server hosting company will have to do that? – ezekielweb Oct 10 '13 at 14:47
  • How big is your data? You can use a pure javascript solution: github.com/maxogden/geojson-js-utils – Alex Leith Oct 13 '13 at 23:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.