Select to view content in your preferred language

Adding Point to Feature Class that has been created using Lat/Long and XY tool

10372
7
Jump to solution
06-18-2014 11:23 AM
AlexTurner
Deactivated User
I am trying to create a custom tool to take user input about point locations and add them into an existing feature class that already contains points that have been located using their Lat/Long values. I set up multiple arcpy.getparameterastext() such as name, size, etc. Latitude and Longitude are also point values, however when I enter everything in and run the tool I get this error...TypeError: expect single [X,Y[,Z[,M]]]

I assume it has something to do with setting up the XY coordinates but I am not sure how to fix this. It is probably something simple I am just not finding. Does anyone know how to fix this?
0 Kudos
1 Solution

Accepted Solutions
MattEiben
Deactivated User
If you are accepting the Lat/Lons + other attributes and plain text, you could use a Insert Cursor like this:

with arcpy.da.InsertCursor(FeatureClass,["SHAPE@XY","Name","Size"]) as cursor:     cursor.insertRow(((-111.0449838888, 32.657),"Name","Size"))


You could do this with a Point Geometry object instead, though it's not as direct:

with arcpy.da.InsertCursor(FeatureClass,["SHAPE@","Name","Size"]) as cursor:     point = arcpy.PointGeometry(arcpy.Point(-111.0449838888, 32.657),arcpy.SpatialReference(4263))     cursor.insertRow((point,"Name","Size"))

View solution in original post

0 Kudos
7 Replies
by Anonymous User
Not applicable
Original User: mzcoyle

You are trying to input the wrong data type. It looks like whatever is throwing the error is expecting a single and you are inputting a point geometry array of some kind.
0 Kudos
MattEiben
Deactivated User
If you are accepting the Lat/Lons + other attributes and plain text, you could use a Insert Cursor like this:

with arcpy.da.InsertCursor(FeatureClass,["SHAPE@XY","Name","Size"]) as cursor:     cursor.insertRow(((-111.0449838888, 32.657),"Name","Size"))


You could do this with a Point Geometry object instead, though it's not as direct:

with arcpy.da.InsertCursor(FeatureClass,["SHAPE@","Name","Size"]) as cursor:     point = arcpy.PointGeometry(arcpy.Point(-111.0449838888, 32.657),arcpy.SpatialReference(4263))     cursor.insertRow((point,"Name","Size"))
0 Kudos
by Anonymous User
Not applicable
Original User: at8808

Here is some of the code I am working with, all I am really trying to do is add another row of information to the table and then figure out how to have the new point show up on the map as well. Maybe insertcursor is not the correct tool?

#Define the variables for input
StName = arcpy.GetParameterAsText(0)
StNameSort = arcpy.GetParameterAsText(1)
StAbbr = arcpy.GetParameterAsText(2)
Status = arcpy.GetParameterAsText(3)
StNum = arcpy.GetParameterAsText(4)
SqFt = arcpy.GetParameterAsText(5)
Addr = arcpy.GetParameterAsText(6)
City = arcpy.GetParameterAsText(7)
State = arcpy.GetParameterAsText(8)
Postal = arcpy.GetParameterAsText(9)
Phone = arcpy.GetParameterAsText(10)
Lat = arcpy.GetParameterAsText(11)
Long = arcpy.GetParameterAsText(12)
Open = arcpy.GetParameterAsText(13)
Current = "Layers_Stores_BPS_Current" #Path to Current  Locations
Future = "Layers_Stores_BPS_Future" #Path to Future Locations
All = "Layers_Stores_BPS_All" #Path to All  Locations


#Define the fields that will be filled
StNameField = "StoreName"
StNameSortField = "StoreNameShort"
StAbbrField = "StoreAbbrev"
StatusField = "Status"
StNumField = "StoreNum"
SqFtField = "SqFt"
AddrField = "Address"
CityField = "City"
StateField = "State"
PostalField = "PostalCode"
PhoneField = "Phone"
LatField = "Latitude"
LongField = "Longitude"
OpenField = "OpenDate"


#If/Then to update correct tables based on Status
if Status == "Current":

#Inserts new row into Current Locations table
    cursor = arcpy.da.InsertCursor(Current, (StNameField, StNameSortField, StAbbrField, StatusField, StNumField, SqFtField, AddrField, CityField,
                                             StateField, PostalField, PhoneField, LatField, LongField, OpenField))
   
    cursor.insertRow((StName, StNameSort, StAbbr, Status, StNum, SqFt, Addr, City,
                      State, Postal, Phone, Lat, Long, Open))
    del cursor
0 Kudos
AlexTurner
Deactivated User
I tried your solution as you can see below but I received the same error. The error message identified line 50 which is the "cursor.insertRow..." line.


#If/Then to update correct tables based on Status
if Status == "Current":

#Inserts new row into Current Locations table
    with arcpy.da.InsertCursor(Current, ["SHAPE@XY", StNameField, StNameSortField, StAbbrField, StatusField, StNumField, SqFtField, AddrField, CityField,
                                         StateField, PostalField, PhoneField, LatField, LongField, OpenField]) as cursor:
       
        cursor.insertRow(((Lat, Long), StName, StNameSort, StAbbr, Status, StNum, SqFt, Addr, City, State, Postal, Phone, Lat, Long, Open))
       
   
   
    del cursor
0 Kudos
by Anonymous User
Not applicable
Original User: eibenm

Since you're accepting all your parameters as text, make sure to convert the appropriate ones to ints, floats, etc...

Your (Lat, Long) should be (float(Lat), float(Long)) since ArcMap doesn't know what to do with string coordinates.  This may apply to other fields too based off your field definitions ...

EDIT:

It should be (float(Long), float(Lat))
ArcMap expects your Longitude first
0 Kudos
AlexTurner
Deactivated User
Well, the points are finally adding to the table and showing up in the map but they are not in the correct places. I think ArcMap is reading the Lat/Long values I am putting in as coordinate values. I have tried putting it in Lat first and Long first, neither works. Is there a simple way to make sure they are read as Lat/Long or to convert them to coordinate values?

EDIT:
When I pull up the Identify window and look at the location field the values for Decimal Degree, which is where Lat/Long would be are -0.000835 0.000305
The values I put in were -93 and 34

Under kilometers the values were -0.093 0.034. I am not sure if that helps clarify anything but I am lost as to where to go now

EDIT2:
So I noticed that one of my tables actually placed the point in the correct location, but the other one didnt. However they have the same code. The future table is the one that is not working and places the point using the values above. The All table places the point perfectly. The two codes look identical, am I missing something?

#Insert new row into Future table

    with arcpy.da.InsertCursor(Future, ["SHAPE@XY", StNameField, StNameSortField, StAbbrField, StatusField, StNumField, SqFtField, AddrField, CityField,
                                         StateField, PostalField, PhoneField, LatField, LongField, OpenField]) as cursor:
       
        cursor.insertRow(((float(Long), float(Lat)), StName, StNameSort, StAbbr, Status, StNum, SqFt, Addr, City, State, Postal, Phone, Lat, Long, Open))
       
   
   
    del cursor
#Insert new row into All table  
    with arcpy.da.InsertCursor(All, ["SHAPE@XY", StNameField, StNameSortField, StAbbrField, StatusField, StNumField, SqFtField, AddrField, CityField,
                                         StateField, PostalField, PhoneField, LatField, LongField, OpenField]) as cursor:
       
        cursor.insertRow(((float(Long), float(Lat)), StName, StNameSort, StAbbr, Status, StNum, SqFt, Addr, City, State, Postal, Phone, Lat, Long, Open))
       
   
   
    del cursor
0 Kudos
by Anonymous User
Not applicable
Original User: at8808

Well I figured it out. Simply had to use the arcpy.SpatialReference tool to set the spatial reference and then the arcpy.PointGeometry tool to create the point and apply the Spatial Reference. That was then entered into the SHAPE@ geometry object through the InsertCursor
0 Kudos