I am building an application and I want it to have the following functionality.

I have a table of points and I would like to be able to query that table for a specific point and get all of the polygons that it is INSIDE of.

For example. If I have a point in Austin,TX, I would like my application to return a reference to a Austin, Texas, United States, North America, essentially grabbing all "parent" polygons. At the same time I would like to be able to do the reverse and say "give me all of the points in the United States", or "give me the points in Texas".

I know how to do the queries with PostGIS, and up until now, I have been loading various shape files into my database from gadm. I have all admin levels, but I am missing American cities so now I have to go download that data. My hunch is I am missing other data besides American cities so I started looking at GeoServer and MapServer.

My question is, am I going about this the wrong way?

Can I query a GeoServer service for the same type of information (giving me all points in a polygon)? Am I wasting my time loading these shapefiles into PostGIS? I am so new to this stuff so any information helps.

PS, right now I am using QGIS to explore the data. Not sure if that helps answer the questions or not

  • There's no such thing as a GeoServer. GeoServer is a software product that allows one to configure a number of services, such as WMS, WCS, WFS etc. Similarly MapServer is a software product that allows one to configure a number of services... – nmtoken Nov 17 '16 at 17:13
  • I think it is still ok to say "a GeoServer" the same way someone says "an Apache server". Afterall, I would be creating an actual running server. – tylerism Nov 17 '16 at 17:22
  • 1
    A GeoServer instance, or a GeoServer server, would be equivalent linguistically, but it really doesn't make any sense as far as questions of spatial functionality. – nmtoken Nov 17 '16 at 17:28
  • Are you going about this the wrong way?<br> That is hard to say... Are you building a web application with javascript? If so, here are alternative ways to accomplish your task:<br> You could do these spatial queries on the front end using turf.js turf.within will give you all points within a polygon,<br> turf.inside will give you a boolean for if a point is in a polygon. Or Run your queries in postGIS, create tables of the data and have your application read from the tables. – Owen J Lamb Nov 17 '16 at 20:32

Well even a GeoServer service you are going to have to feed with data. That could mean just linking your shapefiles and not loading them or loading them in PostGIS and pointing GeoServer at them.

In the end I think you have the greatest breath of flexibility with having your data in PostGIS if you plan to do more than render them because GeoServer would still be limited to what it can do with shapefiles.

That said, for this kind of problem my go to solution is:

Front end something like Leaflet or OpenLayers (with AngularJS or JQuery).

Back end: PostGIS, with middleware between either being (PHP, Node, or ASP.NET),

and then I just create functions in PostGIS that take input args (usually as json because AngularJS automatically converts forms to JSON and JQuery can too), select the bits from the JSON input, output a GeoJSON feature collection which both Leaftlet and OpenLayers know what to do with.

It avoids the need of yet another service like GeoServer.

Now if I need serious styling, then I go to GeoServer and MapServer for help.

I forgot to add, that our upcoming book, in draft on pgRouting - https://locatepress.com/pgrouting covers this approach (using PHP, Leaflet, AngularJS, and PostgreSQL stored functions that use PostGIS and pgRouting functions. The source code you can find here: http://www.postgis.us/downloads/pgr_1e/pgr_1e_code_data.zip (in folder code/app)

  • Awesome. Thank you for the thorough answer. I guess I was just looking for the proper approach. Do you happen to know how the big players get all of their geospatial data in regards to country, city, etc.. boundaries? For example, Google or Bing. Are they just collecting as much as the open source info that they can find? Creating it themselves? – tylerism Nov 18 '16 at 16:42
  • I think both Google and Bing spend a ton of money creating their own data. I don't think they use much opensource. I would say OpenStreetMap is probably the most complete of open source data. OpenStreetMap data is used by MapQuest, FourSquares, MapBox (or at least they used to) – LR1234567 Nov 18 '16 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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