Select to view content in your preferred language

insert DMS coordinates in python tool

2069
7
08-22-2013 06:17 AM
bogdanpalade1
Deactivated User
Dear friends,

I want to make a simple tool where one could insert DMS coordinates and the tool would generate a point shapefile containing one point at the specified coordinates.

For the tool I have three parameters:

1. Output folder (type folder)
2. X coordinates (type string)
3. Y Coordinates (Type string)

If I run it inserting Decimal degrees coordinates, it works fine. If I am inserting DMS coordinates (for example 44°27'2.714"W  39°16'38.993"N) I get an error where it says that "input value is not numeric"). What should I do to make it work with DMS? Should I write the DMS in another way?

Here is the code:

outFolder = arcpy.GetParameterAsText(0)
arcpy.env.workspace = outFolder
outSHP = "MyShape.shp"
sr = arcpy.CreateSpatialReference_management("path to the WGS 1984.proj")
arcpy.CreateFeatureclass_management(outFolder, outSHP, "POINT", "#", "#", "#", sr)
Xcoord = arcpy.GetParameterAsText(1)
Ycoord = arcpy.GetParameterAsText(2)
cur = arcpy.InsertCursor(outSHP)
bgd = cur.newRow()
pnt = arcpy.CreateObject("Point")
pnt.X = Xcoord
pnt.Y = Ycoord
bgd.shape = pnt
cur.insertRow(bgd)
del cur, bgd


Thank you very much!
Tags (2)
0 Kudos
7 Replies
markdenil
Frequent Contributor
It is fairly simple to convert DMS to DD.
((((seconds / 60) + minutes) / 60) + degrees) * hemisphere)

for W or S, hemisphere = -1
for E or N, hemisphere = 1

There is a bit of fun parsing the string to its components, but that's not too hard either.

If you really are just stroking the coordinates in as command arguments, then it is even simpler to parse.
0 Kudos
bogdanpalade1
Deactivated User
It is fairly simple to convert DMS to DD.
((((seconds / 60) + minutes) / 60) + degrees) * hemisphere)

for W or S, hemisphere = -1
for E or N, hemisphere = 1

There is a bit of fun parsing the string to its components, but that's not too hard either.

If you really are just stroking the coordinates in as command arguments, then it is even simpler to parse.



So I understand that the only method would be for me to do the conversion within the script...I thought that there would be a way to simply insert in the tool the coordinates as DMS and arcgis would understand it as such...

Thank you for the reply,

Bogdan
0 Kudos
bogdanpalade1
Deactivated User
[ATTACH=CONFIG]26885[/ATTACH]....something like I have attached
0 Kudos
markdenil
Frequent Contributor
Yes, let the script do it.
No, the tool does not understand the DMS strings.

so, you are stroking it in anyway....
Why not just space delimit the values instead of using all the little marks? (like alt-0176 for °)
to wit:
-44 27 2.714
39 16 38.993

for 44°27'2.714"W 39°16'38.993"N

It would be faster to type and easier to parse.....

Workstation Arc PROJECT can (or could) use DMS input in text files, but that would get rather round-about.
0 Kudos
bogdanpalade1
Deactivated User
I understand...I was hoping there was an easier way...:) didn't want to write a very long script to do this basic thing. Because if I have to parse the text and cover all the possibilities in order to do the calculations ( identify the exact location of degrees, minutes, seconds  - "1 1 1" is very different from "179 55 55") I am afraid I would end up losing an entire week with this thing :))

But...as it appears there s no other way...I thought I would just put like a lot of parameters...one for each D, M,S..and like this I don't have to parse anything..the user will have a bit of harder time filling in 8 different boxes (for hemispheres as well) but...as I m not a python expert this will do just fine.

Thank you for the help,

Bogdan
0 Kudos
markdenil
Frequent Contributor
In python "1 1 1" is is not very different from "179 55 55"
simply split the string on the blanks
which makes a list with three elements
which you reference by index
theList[0] is the degrees
theList[1] is the min
theList[2] is the seconds.
0 Kudos
MarcusCole
New Contributor
As a bonus, you can handle DD and Degree Decimal Minutes input as well. Just calculate the parts that are present and gracefully ignore elements that are absent.
0 Kudos