pandasarcgisgeopandasgoogle-earth

Convert UTM coordinates from excel file to SHAPEFILE points in python?


This image represents a list of components location in UTM coordinates in zone 17S.

However, I would like to visualize them in ArcGis Pro or Google Earth and must be a KMZ/KML or SHAPEFILE. Each coordinate should be displayed as a point, not a polygon

data = [['ROO01', 558635, 9303470],
        ['ROO02', 559203, 9303470]]
columns = ['ID', 'Easthing', 'Northing']
df = pd.DataFrame(data=data, columns=columns)

enter image description here

How could I do that and obtain something like this?

enter image description here


Solution

  • You can use pyproj.

    import geopandas as gpd
    import pyproj
    from shapely.geometry import Point
    
    # https://epsg.io/32717
    proj = pyproj.Proj('EPSG:32717')  # WGS 84 / UTM zone 17S
    lon, lat = proj(df['Easthing'], df['Northing'], inverse=True)
    
    df['geometry'] = list(map(Point, zip(lat, lon)))
    gdf = gpd.GeoDataFrame(df, crs='WGS84')
    gdf.to_file('layer.shp')
    

    Output:

    >>> gdf
          ID  Easthing  Northing                    geometry
    0  ROO01    558635   9303470  POINT (-6.30120 -80.46989)
    1  ROO02    559203   9303470  POINT (-6.30120 -80.46475)
    
    >>> gdf.crs
    <Geographic 2D CRS: EPSG:4326>
    Name: WGS 84
    Axis Info [ellipsoidal]:
    - Lat[north]: Geodetic latitude (degree)
    - Lon[east]: Geodetic longitude (degree)
    Area of Use:
    - name: World.
    - bounds: (-180.0, -90.0, 180.0, 90.0)
    Datum: World Geodetic System 1984 ensemble
    - Ellipsoid: WGS 84
    - Prime Meridian: Greenwich
    
    >>> gdf.info()
    <class 'geopandas.geodataframe.GeoDataFrame'>
    RangeIndex: 2 entries, 0 to 1
    Data columns (total 4 columns):
     #   Column    Non-Null Count  Dtype   
    ---  ------    --------------  -----   
     0   ID        2 non-null      object  
     1   Easthing  2 non-null      int64   
     2   Northing  2 non-null      int64   
     3   geometry  2 non-null      geometry
    dtypes: geometry(1), int64(2), object(1)
    memory usage: 192.0+ bytes