Chapter 2 — Practice Spatial Points Lines Polygons cont.

Spatial Points, Lines and Polygons in Python

GeoSense ✅
5 min readJan 10, 2023

--

Objectives for this part:

  • Create new spatial objects (points, lines, polygons)
  • Assign the correct projection or CRS
  • Create points from a table or csv of lat and lon

Creating GeoDataFrame Geometries

# Import necessary modules first
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point, LineString, Polygon
import fiona
import matplotlib.pyplot as plt
plt.style.use('bmh') # better for plotting geometries vs general plots.

First, create an empty GeoDataFrame and create a new column called geometry that will contain our Shapely objects:

# Create an empty geopandas GeoDataFrame
newdata = gpd.GeoDataFrame()
print(newdata)
Empty GeoDataFrame
Columns: []
Index: []

GeoDataFrame Components

  • data: a pandas.DataFrame, dictionary, or empty list [] containing an desired attribute data. Use [] if no data is
  • crs: Coordinate Reference System of the geometry objects. Can be anything accepted by pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:4326”) or a WKT string.
  • geometry: Column name in a DataFrame to use as geometry or Shapely point, line, or polygon object.

--

--

GeoSense ✅
GeoSense ✅

Written by GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️ https://www.tnmthai.com/medium

No responses yet