0

I have a shapefile generated by the ESRI product suite. I do not have any ESRI products and my budget does not support their purchase. Aside from fiscal issues, there may be technical limitations with deploying ESRI products but that's a moot point since we have no money.

Using .NET and, if necessary, open source libraries, how can I read my shape file data and return the polygon that contains a latitude and longitude coordinate? I see this being built as service code and given a coordinate, it returns the polygon. Conceptually not too difficult but I'm not sure which libraries out there will help with this.

Thoughts?

edit #1 - I'd settle for returning the polygon's ID or description or some other string property. If I want more info, I will fetch that using the polygon's ID or name or ???

edit #2 - The solution should be something I can call from a service. For example, a library I can call from my .NET code would work just fine. An application that must be installed and data entered through its UI will not work since my application will be deployed.

nmtoken
  • 13,355
  • 5
  • 38
  • 87
DenaliHardtail
  • 3,177
  • 4
  • 34
  • 68
  • Esri is not the only option you have for working with your shapefiles. Refer to this post which lists free software, many which work with shapefiles. This should be a good starting point. My personal recommendation: QGIS. http://gis.stackexchange.com/questions/12105/what-free-programs-should-every-gis-user-have-installed – evv_gis Nov 03 '14 at 18:19
  • The challenge of "returning a polygon" is the data structure in which it is returned. This is generally dictated by the software you have available. – Vince Nov 03 '14 at 18:26
  • This might fill your needs: http://gis.stackexchange.com/questions/73279/qgis-point-sampling-tool-really-slow-for-polygons and http://gis.stackexchange.com/questions/63326/qgis-create-point-data-attribute-as-the-name-of-the-polygon-it-falls-in – AndreJ Nov 03 '14 at 18:56

2 Answers2

1

SpatiaLite is one of the many potential solutions. It probably depends a bit on whether the shapefile you are working on is dynamic or its always the same file (or one of a few files of static content), but loading the shapefile using VirtualShape virtual table extension or the ImportSHP() SQL function will make it available in SpatiaLite.

Then you can use any of the SpatiaLite spatial functions such as ST_Contains or ST_Intersects (depend on what you mean by "contains" - for example, what happens if the point is on the border?) to select the point including some or all of the attributes.

Depending on the number of rows, you may want to use a spatial index to assist with the search, although a full table scan isn't usually a problem for up to a few thousand polygons. Note: SpatiaLite requires the index to be defined, and to be explicitly included in each search operation. It is not enough to just create the index.

Use from C# is no problem - just use System.Data.SQLite and load the DLL / shared library as an extension.

BradHards
  • 12,881
  • 2
  • 37
  • 70
0

There are a ton of free software out there that will allow you to export the polygon and see the lat long coordinates of it.

Your question was answered previously How to export Polygons to CSV with coordinates?

jonathanw
  • 138
  • 9
  • I think the question is more about: "I have a coordinate pair and want to get the polygon that is around this point". Like the appropriate town, county or state border. – AndreJ Nov 03 '14 at 18:37
  • @AndreJ, this is correct. Specifically, given a coordinate, what township contains the coordinate. – DenaliHardtail Nov 03 '14 at 18:49
  • Easily done with a spatial join http://www.qgistutorials.com/en/docs/points_in_polygon.html or http://www.qgistutorials.com/en/docs/performing_spatial_joins.html – jonathanw Nov 03 '14 at 19:05