GeoPandas is an open source project to make working with geospatial data in python easier, I installed the library via PyPi
Sample data files can be downloaded from here
import traceback
import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import geopandas
def makePline(pnts, model, color):
pline = Db.Polyline(pnts)
pline.setColorIndex(color)
model.appendAcDbEntity(pline)
def PyRxCmd_doit():
try:
db = Db.curDb()
model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite)
gdf = geopandas.read_file("E:/townssurvey_shp/TOWNSSURVEY_ARC_GENCOAST.shp")
#gdf = geopandas.read_file("E:/110m_cultural/ne_110m_admin_0_countries.shp")
#do MultiPolygon first
gdf0 = gdf.loc[gdf.geometry.geometry.type=='MultiPolygon']
for mp in list(gdf0.geometry):
for p in mp.geoms:
makePline(list(p.exterior.coords), model, 1)
gdf1 = gdf.loc[gdf.geometry.geometry.type=='Polygon']
for p in gdf1.geometry:
makePline(list(p.exterior.coords), model, 2)
gdf2 = gdf.loc[gdf.geometry.geometry.type=='LineString']
for p in gdf2.geometry:
makePline(list(p.coords), model, 3)
except Exception as err:
traceback.print_exception(err)
PyRx Python for AutoCAD
No comments:
Post a Comment