Commercial Development in Baltimore, Maryland

Using Python to analyze commercial development over the past century, both spatially and temporally.

Project 2

Objective

To create a map that shows commercial development in Baltimore, MD over the last century, both spatially and temporally.

Process

Real_Property = QgsVectorLayer('C:/Users/ges_student/Desktop/Project_2/Shapefiles/Real_Property_Proj.gpkg', 'Real_Property')
Real_Property.isValid()
# Should Return "True"
QgsProject.instance().addMapLayer(Real_Property)
# Should return "<qgis._core.QgsVectorLayer object at 0x000001714E5500D8>"

renderer = Real_Property.renderer()
renderer
#Should return "<qgis._core.QgsSingleSymbolRenderer object at 0x000001F6CBC06DC8>"
symbol = renderer.symbol()
symbol.dump()
#Should return 'FILL SYMBOL (1 layers) color 152,125,183,255'
symbol.setColor(Qt.gray)
Real_Property.triggerRepaint()

layer_tree = iface.layerTreeView()
layer_tree.refreshLayerSymbology(Real_Property.id())

selection = Real_Property.getFeatures(QgsFeatureRequest(). setFilterExpression(u'"YEAR_BUILD" >= 1900 and "YEAR_BUILD" <= 2018 and "USEGROUP" = \'C\''))
Real_Property.selectByIds([s.id() for s in selection])
iface.mapCanvas().zoomToSelected()

QgsVectorFileWriter.writeAsVectorFormat(Real_Property, r'C:/Users/ges_student/Desktop/Project_2/Shapefiles/Comm_Poly_Test2.gpkg', 'utf-8', Real_Property.crs(),'GPKG', True)

Comm_Poly_Test2 = QgsVectorLayer('C:/Users/ges_student/Desktop/Project_2/Shapefiles/Comm_Poly_Test2.gpkg', 'Real_Property')
Comm_Poly_Test2.isValid()
# Should Return "True"
QgsProject.instance().addMapLayer(Comm_Poly_Test2)

Add in the Real_Property Layer

Real_Property = QgsVectorLayer('C:/Users/ges_student/Desktop/Project_2/Shapefiles/Real_Property_Proj.gpkg', 'Real_Property')
Real_Property.isValid()
# Should Return "True"
QgsProject.instance().addMapLayer(Real_Property)
# Should return "<qgis._core.QgsVectorLayer object at 0x000001714E5500D8>"

Change the fill color to gray

renderer = Real_Property.renderer()
renderer
#Should return "<qgis._core.QgsSingleSymbolRenderer object at 0x000001F6CBC06DC8>"
symbol = renderer.symbol()
symbol.dump()
#Should return 'FILL SYMBOL (1 layers) color 152,125,183,255'
symbol.setColor(Qt.gray)
Real_Property.triggerRepaint()

Update the layer tree

layer_tree = iface.layerTreeView()
layer_tree.refreshLayerSymbology(Real_Property.id())

perform a selection commercial lots present during the desired time period in twenty year increments.

selection = Real_Property.getFeatures(QgsFeatureRequest(). setFilterExpression(u'"YEAR_BUILD" >= 1900 and "YEAR_BUILD" <= 2018 and "USEGROUP" = \'C\''))
Real_Property.selectByIds([s.id() for s in selection])
iface.mapCanvas().zoomToSelected()

Script Selection alt text

Save this selection to file as a new Shapefiles

QgsVectorFileWriter.writeAsVectorFormat(Real_Property, r'C:/Users/ges_student/Desktop/Project_2/Shapefiles/Comm_Poly_Test2.gpkg', 'utf-8', Real_Property.crs(),'GPKG', True)

Add the new shapefile to the map.

Comm_Poly_Test2 = QgsVectorLayer('C:/Users/ges_student/Desktop/Project_2/Shapefiles/Comm_Poly_Test2.gpkg', 'Real_Property')
Comm_Poly_Test2.isValid()
# Should Return "True"
QgsProject.instance().addMapLayer(Comm_Poly_Test2)

New Layer Addition alt text

Results

alt text

alt text

alt text