I have a .csv file with longitude, latitude representing a point on map. And another column that I will use as weights for these maps. I want to calculate weighted mean center for all the points using ArcPy.
This is what I've tried so far:
import pandas as pd
import arcpy
df = pd.read_csv("data.csv")
longs = df['Longitude'].tolist()
lats = df['Latitude'].tolist()
wts = df['Weights'].tolist()
point = arcpy.Point()
pointGeoms = []
for idx in range(len(longs)):
point.X = float(lats[idx])
point.Y = float(longs[idx])
point.M = int(wts[idx])
pointGeoms.append(arcpy.PointGeometry(point))
arcpy.CopyFeatures_management (pointGeoms,"centroids.shp")
Above code is for generating shapefile. Below code is for calculating weighted means.
import arcpy
workspace = r"C:\Users\sam"
input_FC = "centroids.shp"
weight_field = "M"
try:
# Set the workspace to avoid having to type out full path names
arcpy.env.workspace = workspace
# Process: Mean Center...
arcpy.MeanCenter_stats(input_FC, MEAN_output, "#", "#", "#")
except:
# If an error occurred when running the tool, print out the error message.
print(arcpy.GetMessages())
I am not able to get any positive outcomes from both the codes. The shapefile generated by first code shows empty point values in ArcGIS Pro. And the second code generates a point randomly placed very far away from any point of interest.