1

I have a large csv with approximately 5 million records that have latitude and longitude coordinates that I tried converting to a shapefile with geopandas so I didn't have to hit my desktop ArcMap with that much information. My code is:

import pandas as pd
import geopandas as gpd
from shapely.geometry import Point

df = pd.read_csv('leases.csv')
geometry = [Point(xy) for xy in zip(df.longitude,df.latitude)]
df = df.drop(['longitude','latitude'], axis=1)
crs = {'init':'epsg4326'}
gdf = gpd.GeoDataFrame(df, crs=crs, geometry=geometry)
gdf.to_file(driver='ESRI Shapefile',filename="leases.shp")

This code runs fine and I get a point shapefile that I can load in ArcMap, but when I look at the attribute table, the records are getting messed up. One issue there are duplicate records showing up in the attribute table that don't exist, but the number of records is still correct. Another issue is in the picture below where records are just showing up incorrectly. enter image description here

I have checked the csv and and none of these issues are in there. I'm trying to figure out if this is an ArcMap issue loading this, or a geopandas issue. I have tried running the code with just Arkansas by itself (about 165,000 records) and when I load that in ArcMap it is just fine and these issues don't occur.

1
  • Extra delimiters in your values field could cause that, such as commas in the values of a comma delimited dataset.
    – Paul
    Commented Jul 29, 2017 at 3:51

1 Answer 1

1

Why don't use arcpy? If you'll use ArcMap, I think is the best option:

# import system modules 
import arcpy
from arcpy import env

try:
    # Set the local variables
    in_Table = r"path\to\leases.csv"
    x_coords = "longitude"
    y_coords = "latitude"
    out_Layer = "leases"
    out_dir = r"out\path"

    # Set the spatial reference
    spRef = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"

    # Make the XY event layer...
    arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef)

    # Save to shapefile
    arcpy.FeatureClassToShapefile_conversion(out_Layer, out_dir)

except:
    # If an error occurred print the message to the screen
    print arcpy.GetMessages()
4
  • I will try this. I actually went ahead and tried loading the data and exporting the data frame as a shapefile from ArcMap and got an even more messed up attribute table. I wasn't necessarily trying to work in ArcMap, was just loading there to check if the python code was working.
    – Colton T
    Commented Jul 28, 2017 at 16:15
  • This only creates a layer file, I need a shapefile.
    – Colton T
    Commented Jul 28, 2017 at 16:51
  • Yes, I fixed the code and tested. Now it should work
    – aldo_tapia
    Commented Jul 28, 2017 at 16:59
  • You don't have to run this code in ArcMap. Just execute this in IDLE
    – NULL.Dude
    Commented Jul 29, 2017 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.