I'm attempting to create a feature set using location data from our billing system that contains water meter locations. The location information is in latitude and longitude format so I thought it would be fairly simple to create features from this by inserting the data into the geometry field of the feature. It turns out this is not the case as when I tried just putting in this information, all of my data ended up in Arkansas (I need the points to be in Tennessee). From here I have tried changing the coordinate projection and converting the latitude and longitude to x and y data in feet. This change got my points to be in the correct locations relative to each other but the points are showing to be in the Pacific Ocean.
I'm really at a loss for what is going on and could use some help. We are on an Enterprise Portal version 10.9 and I'm using Python 3.9 if either of those are relevant. I'll go ahead and attach the relevant code that I'm using too.
geometry_layer = model_layer.layers[0]
table_layer = model_layer.tables[0]
for d in data:
if d['Flow'] is None:
flow = None
else:
flow = float(d['Flow'])
if d['Flow_Time'] is None:
flow_time = None
else:
flow_time = dt.datetime.strptime(d['Flow_Time'], '%Y-%m')
if d['Endpoint_SN'] is None:
sn = None
else:
sn = int(d['Endpoint_SN'])
geo = {'attributes':{
'account_full_name': d['Account_Full_Name'],
'account_id': d['Account_ID'],
'endpoint_sn': sn,
'location_address': d['Location_Address_Line1'],
'location_city': d['Location_City'],
'sa_start_date': dt.datetime.strptime(d['SA_Start_Date'], '%Y-%m'),
'read_method': d['Read_Method']
},
###This section is where I'm assuming the problem lies. I'm using a simple coordinate transformation in order to try and get the right x and y values.
'geometry':{
# 'x': float(d['Service_Point_Longitude']),
# 'y': float(d['Service_Point_Latitude']),
'x': (20.902*10**6)*(math.pi/180)*(float(d['Service_Point_Longitude']))*math.cos((math.pi/180)*34.33333333333334),
'y': (20.902*10**6)*(math.pi/180)*(float(d['Service_Point_Latitude'])),
'spatialReference': {'wkid': 102736}
}
}
table = {'attributes':{
'endpoint_sn': sn,
'flow': flow,
'flow_time': flow_time
}
}
geometry_layer.edit_features(adds=[geo])
table_layer.edit_features(adds=[table])
Solved! Go to Solution.
I fixed the issue by changing the wkid to the GCS instead of the PCS and then using the latitude and longitude in the geometry.
Hey, can you by any chance provide some sample longitude/latitude values from the data?
Longitude: -87.388224
Latitude: 36.08589
The spatial reference should actually be 103152
I'm wondering if the problem lies in the feature layer being created in Tennessee state plane instead of web mercator and then just letting pro convert it when it needs to. We have another layer with water meters and this seems to be what it's doing. The spatial reference of the layer is web mercator but each individual point is referenced to Tennessee state plane.
Let me know what you come up with. Thank you.
I fixed the issue by changing the wkid to the GCS instead of the PCS and then using the latitude and longitude in the geometry.
Oh okay, great! Glad to hear you got something working.
Try something like this snippet as a test. It's absolutely not the most efficient way to do it but requires the least amount of change to your existing code. I tried to find the appropriate transformation WKID but came up short. It appears to do the projection, but I can't verify on my end. You'll just need to update the x/y to point to your data, as well as the attributes:
from arcgis.features import FeatureSet
from arcgis.geometry import project
geometry = {
"x": -87.388224,
"y": 36.08589
}
new_geometry = project(geometries=[geometry], in_sr=4326, out_sr=103152)
point_dict = {
"features": [{
"attributes":{
"name": "test",
},
"geometry": new_geometry[0]
}]
}
fs = FeatureSet.from_dict(point_dict)
layer.edit_features(adds=fs)
If this works, then maybe we can streamline things and switch to using a dataframe to do all the required projections at once.