Convert lat/lon to Township/Range/Section with Python/arcpy

7496
5
01-22-2015 12:32 PM
JohnDaues1
New Contributor

We have data in a SQL database that has many records, each with a lat/lon and PLSS (Township, Range, Section). This data was entered by hand and so it is possible that there are errors such that the lat/lon may not lie within the Township/Range/Section. A user could have typed a wrong lat/long or Township/Range/Section.

 

So I'm writing a python script to check that the lat/lon in a given record does indeed lie within the corresponding Township/Range/Section. I have written code to get the lat/lon and Township/Range/Section from the database and put this data into dictionaries. Now I need to test that the lat/lon lies within the Township/Range/Section.

 

Can I use arcpy to do this?

If so, can you give some direction?

Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

If you could get the data into a mappable form, then it becomes a Select By Location operation, selecting the points that fall within the polygons...should you want those that fall outside, simply switch the selection and save your results to a new file, or edit accordingly.  This of course can be done within arcpy geometry objects, but for you to develop the code would be hardly worthwhile.  You could of course simply create your own tool in arctoolbox that emulates the select by location operation but puts in default parameters should you have to do this on a regular basis.

0 Kudos
JohnDaues1
New Contributor

Thanks for the reply. FYI, I'm totally new to GIS programming, but not to Python

So I have a lat/lon (Decimal in Python) ... how to I get these into "mappable form"?

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you have decimal degree data, Longitude and Latitude format, then you can bring in a text file, an excel spreadsheet etc etc.  My real question is why do you need to do this via code when you can complete the task in seconds manually?  If code is needed, then you can find the code snippets in the help files associated with the various tools, for example, Select By Location, is in that link.  The jargon will become familiar when you begin to use the software.  You can also develop a Model in Modelbuilder...but I would begin by familiarizing yourself with the online help for ArcMap 10.2 to assist you in your exploration of the software and it's coding base.

0 Kudos
JohnDaues1
New Contributor

>> My real question is why do you need to do this via code

1. Because I’m a software developer, not a GIS person ☺

2. There are thousands of lat/lon <=> PLSS data points

Thanks for your reply, again. I’ll start again on this tomorrow.

0 Kudos
DanPatterson_Retired
MVP Emeritus

In either case, manually or by code, it can be read easily, if you want to see them, then you will need to familiarize yourself with the interface and if you want to simply code it, the advise would be the same.  For example, if you have flat text files etc, you can use Python's csv module to read in your data, save it as a featurelayer which can then be queried as I suggested in previous posts, and the results exported to another format.  Have fun... code snippets abound on this site.

0 Kudos