Example #1
0
 def test_Neighbors(self):
     sw = Queen.from_dataframe(self.df_tessellation, ids="uID")
     self.df_tessellation["nei_sw"] = mm.Neighbors(self.df_tessellation, sw,
                                                   "uID").series
     self.df_tessellation["nei_wei"] = mm.Neighbors(self.df_tessellation,
                                                    sw,
                                                    "uID",
                                                    weighted=True).series
     check = 5.180555555555555
     check_w = 0.029066398893536072
     assert self.df_tessellation["nei_sw"].mean() == check
     assert self.df_tessellation["nei_wei"].mean() == check_w
 def time_Neighbors(self):
     mm.Neighbors(self.df_tessellation, self.sw, "uID")
Example #3
0
# In[ ]:

for buf in buffers:
    tessellation = gpd.read_file(
        'data/tessellation/{0}_tessellation.shp'.format(buf))
    tessellation['area'] = tessellation.area
    tessellation['lal'] = mm.LongestAxisLength(tessellation).series
    tessellation['circom'] = mm.CircularCompactness(tessellation).series
    tessellation['shapeix'] = mm.ShapeIndex(tessellation, 'lal', 'area').series
    tessellation['rectan'] = mm.Rectangularity(tessellation, 'area').series
    tessellation['fractal'] = mm.FractalDimension(tessellation, 'area').series
    tessellation['orient'] = mm.Orientation(tessellation).series
    distancesw = libpysal.weights.DistanceBand.from_dataframe(tessellation,
                                                              400,
                                                              ids='uID')
    tessellation['freq'] = mm.Neighbors(tessellation, distancesw, 'uID').series
    tessellation['car'] = mm.AreaRatio(tessellation, buildings, 'area',
                                       mm.Area(buildings).series)
    tessellation['gini_area'] = gini_fn(tessellation, 'area', distancesw,
                                        'uID')
    tessellation['gini_car'] = gini_fn(tessellation, 'car', distancesw, 'uID')
    tessellation.to_file('data/tessellation/{0}_tessellation.shp'.format(buf))

# In[ ]:

cadastre = gpd.read_file('data/cadastre/Zurich_cadastre.shp')

cadastre['area'] = tessellation.area
cadastre['lal'] = mm.LongestAxisLength(cadastre).series
cadastre['circom'] = mm.CircularCompactness(cadastre).series
cadastre['shapeix'] = mm.ShapeIndex(cadastre, 'lal', 'area').series
streets["mdsAre"] = mm.Reached(streets,
                               tess,
                               "nID",
                               "nID",
                               spatial_weights=str_q1,
                               mode="sum").series

blg_q1 = libpysal.weights.contiguity.Queen.from_dataframe(blg)

blg["libNCo"] = mm.Courtyards(blg, "bID", blg_q1).series
blg["ldbPWL"] = mm.PerimeterWall(blg, blg_q1).series

blocks["ldkAre"] = mm.Area(blocks).series
blocks["ldkPer"] = mm.Perimeter(blocks).series
blocks["lskCCo"] = mm.CircularCompactness(blocks, "ldkAre").series
blocks["lskERI"] = mm.EquivalentRectangularIndex(blocks, "ldkAre",
                                                 "ldkPer").series
blocks["lskCWA"] = mm.CompactnessWeightedAxis(blocks, "ldkAre",
                                              "ldkPer").series
blocks["ltkOri"] = mm.Orientation(blocks).series

blo_q1 = libpysal.weights.contiguity.Queen.from_dataframe(blocks, ids="bID")

blocks["ltkWNB"] = mm.Neighbors(blocks, blo_q1, "bID", weighted=True).series
blocks["likWBB"] = mm.Count(blocks, blg, "bID", "bID", weighted=True).series

tess.to_file("files/elements.gpkg", layer="tessellation", driver="GPKG")
blg.to_file("files/elements.gpkg", layer="buildings", driver="GPKG")
blocks.to_file("files/elements.gpkg", layer="blocks", driver="GPKG")
streets.to_file("files/elements.gpkg", layer="streets", driver="GPKG")