def test_get_shp(self): path = pf.get_shp("subte-estaciones") exp_path = pf.get( "shp/transporte/subte-estaciones/estaciones_de_subte") self.assertEqual(path, exp_path) path = pf.get_shp("estaciones_de_subte") exp_path = pf.get( "shp/transporte/subte-estaciones/estaciones_de_subte") self.assertEqual(path, exp_path)
def main(buffers_dir=None, divisions=DIVISIONS, division_names=DIVISION_NAMES, divisions_dir=pf.DIVISIONS_DIR, empty_shps_dir=EMPTY_SHPS_DIR, recalculate=False): p = None p_counter = 0 for buffer_dir in pf.iter_buffer_dirs(buffers_dir): for division, division_name in zip(divisions, division_names): weights_path = pf.get_weights_path(buffer_dir, division_name) if not os.path.isfile(weights_path) or recalculate: division_path = pf.get_shp(division) p = Process(target=calculate_intersect_weights, args=(division_path, buffer_dir, weights_path, empty_shps_dir)) print("Start process of calculating intersections between", os.path.basename(division_path), "and", os.path.basename(buffer_dir), "...") p.start() p_counter += 1 if p_counter >= 5 and p_counter % 5 == 0: p.join() if p: p.join() print("Intersections calculation complete.")
def test_reproject_point(self): shp_path = pf.get_shp("RADIO") lat, lon = -34.567277, -58.440509 point = reproject_point(lat, lon, shp_path) reproj_coords = list(point.coords)[0] exp_reproj_coords = (1476458.5151069912, -2797102.116439601) self.assertAlmostEqual(reproj_coords[0], exp_reproj_coords[0]) self.assertAlmostEqual(reproj_coords[1], exp_reproj_coords[1])
def main( buffers_dir=None, divisions=DIVISIONS, division_names=DIVISION_NAMES, divisions_dir=pf.DIVISIONS_DIR, empty_shps_dir=EMPTY_SHPS_DIR, recalculate=False, ): p = None p_counter = 0 for buffer_dir in pf.iter_buffer_dirs(buffers_dir): for division, division_name in zip(divisions, division_names): weights_path = pf.get_weights_path(buffer_dir, division_name) if not os.path.isfile(weights_path) or recalculate: division_path = pf.get_shp(division) p = Process( target=calculate_intersect_weights, args=(division_path, buffer_dir, weights_path, empty_shps_dir) ) print( "Start process of calculating intersections between", os.path.basename(division_path), "and", os.path.basename(buffer_dir), "...", ) p.start() p_counter += 1 if p_counter >= 5 and p_counter % 5 == 0: p.join() if p: p.join() print("Intersections calculation complete.")
import os import sys import zipfile import shapefile import glob from shapely.ops import cascaded_union import path_finders as pf from geo_utils import iter_shp_as_shapely import geo_utils import utils BASE_DIR = pf.get("shp/transporte") BUFFER_DIR = "buffers" BUFFERS = [300, 500, 750, 1000, 1500, 2000] CONTEXT_SHP = pf.get_shp("comunas_caba_censo_2010") def _create_shp_name(shp_dir, distance): return os.path.basename(shp_dir) + "-buffer" + unicode(distance) def _create_shp_path(directory, shp_name, buffer_dir): return os.path.join(os.path.dirname(directory), buffer_dir, shp_name, shp_name) def write_shapefile(sf_est, shapely_shapes, shp_path): # creating a new shapefile for buffers w = shapefile.Writer(shapefile.POLYGON)
def test_prj_to_proj4(self): shp_path = pf.get_shp("RADIO") crs = prj_to_proj4(shp_path) exp_crs = '+proj=tmerc +ellps=intl +a=6378388.0 +f=297.0 +pm=0.0 +x_0=100000.0 +y_0=100000.0 +lon_0=-58.4627 +lat_0=-34.6297166 +units=m +to_meter=1.0 +axis=enu +no_defs' self.assertEqual(crs.to_proj4(), exp_crs)
from __future__ import print_function from __future__ import with_statement import os import sys from rtree import index import json from multiprocessing import Process import path_finders as pf import geo_utils # DIVISIONS = ["fracciones_caba_censo_2010", "radios_censo_2010"] DIVISIONS = ["radios_censo_2010"] # DIVISION_NAMES = ["fracciones", "radios"] DIVISION_NAMES = ["radios"] EMPTY_SHPS_DIR = [pf.get_shp("espacios-verdes-privados"), pf.get_shp("espacios-verdes-publicos")] def save_to_json(divisions_weights, json_path): """Save calculated weights into a json file.""" with open(json_path, "wb") as f: json.dump(divisions_weights, f, indent=4) def create_spatial_index(shapes): """Create and rtree optimized spatial index from shapes. Args: shapes (list): Shapely objects. """ shapes_idx = index.Index()
from __future__ import print_function from __future__ import with_statement import os import sys from rtree import index import json from multiprocessing import Process import path_finders as pf import geo_utils # DIVISIONS = ["fracciones_caba_censo_2010", "radios_censo_2010"] DIVISIONS = ["radios_censo_2010"] # DIVISION_NAMES = ["fracciones", "radios"] DIVISION_NAMES = ["radios"] EMPTY_SHPS_DIR = [pf.get_shp("espacios-verdes-privados"), pf.get_shp("espacios-verdes-publicos")] def save_to_json(divisions_weights, json_path): """Save calculated weights into a json file.""" with open(json_path, "wb") as f: json.dump(divisions_weights, f, indent=4) def create_spatial_index(shapes): """Create and rtree optimized spatial index from shapes. Args: shapes (list): Shapely objects. """