Commit 41368c59 authored by Nicolas Garcia Ospina's avatar Nicolas Garcia Ospina
Browse files

Fixed attribute names and geometry issues

parent ed7daa2e
Pipeline #21823 passed with stage
in 4 minutes and 46 seconds
...@@ -66,4 +66,4 @@ class DataSource: ...@@ -66,4 +66,4 @@ class DataSource:
os.path.join(pathname, raster_files_index) os.path.join(pathname, raster_files_index)
) )
self.built_pixel_values = built_pixel_values self.built_pixel_values = built_pixel_values
self.method_id = source_id self.source_id = source_id
...@@ -33,7 +33,7 @@ import multiprocessing ...@@ -33,7 +33,7 @@ import multiprocessing
# Add a logger printing error, warning, info and debug messages to the screen # Add a logger printing error, warning, info and debug messages to the screen
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.DEBUG) logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(sys.stdout)) logger.addHandler(logging.StreamHandler(sys.stdout))
logger.info("Launching obmgapanalysis") logger.info("Launching obmgapanalysis")
...@@ -69,7 +69,7 @@ def multiprocess_chunk(quadkey_batch): ...@@ -69,7 +69,7 @@ def multiprocess_chunk(quadkey_batch):
""" """
# Create DataSource instance to be used by all child processes # Create DataSource instance to be used by all child processes
datasource = DataSource(**datasource_config) datasource = DataSource(**datasource_config)
logger.debug( logger.info(
"DataSource raster files are registered in {}".format( "DataSource raster files are registered in {}".format(
os.path.join(datasource.pathname, datasource_config["raster_files_index"]) os.path.join(datasource.pathname, datasource_config["raster_files_index"])
) )
...@@ -87,8 +87,8 @@ def multiprocess_chunk(quadkey_batch): ...@@ -87,8 +87,8 @@ def multiprocess_chunk(quadkey_batch):
# Build a list with all tiles with reported built-up areas # Build a list with all tiles with reported built-up areas
build_up_areas = [] build_up_areas = []
try: for quadkey in quadkey_batch:
for quadkey in quadkey_batch: try:
result = TileProcessor.get_build_up_area( result = TileProcessor.get_build_up_area(
quadkey=quadkey, quadkey=quadkey,
database=roads_database, database=roads_database,
...@@ -99,11 +99,16 @@ def multiprocess_chunk(quadkey_batch): ...@@ -99,11 +99,16 @@ def multiprocess_chunk(quadkey_batch):
) )
if result is not None: if result is not None:
build_up_areas.append(result) build_up_areas.append(result)
if build_up_areas:
# Write output into a csv file except Exception as e:
FileProcessor.write_tiles_to_csv(build_up_areas, output_pathname) logger.info("Error in quadkey: {}".format(quadkey))
finally: logger.info("Error caught: {}".format(e))
roads_database.connection.close()
if build_up_areas:
# Write output into a csv file
FileProcessor.write_tiles_to_csv(build_up_areas, output_pathname)
roads_database.connection.close()
def multiprocess_csv(csv_filepath): def multiprocess_csv(csv_filepath):
......
...@@ -128,7 +128,7 @@ class TileProcessor: ...@@ -128,7 +128,7 @@ class TileProcessor:
if results: if results:
results_geodataframe = geopandas.GeoDataFrame.from_features(results) results_geodataframe = geopandas.GeoDataFrame.from_features(results)
built_area_geometry = results_geodataframe.unary_union built_area_geometry = results_geodataframe.unary_union
return built_area_geometry return built_area_geometry.buffer(0)
@staticmethod @staticmethod
def clip_to_tile_extent(polygon, tile): def clip_to_tile_extent(polygon, tile):
...@@ -214,8 +214,10 @@ class TileProcessor: ...@@ -214,8 +214,10 @@ class TileProcessor:
geometry (shapely.geometry.polygon.Polygon): Polygon object resulting from the geometry (shapely.geometry.polygon.Polygon): Polygon object resulting from the
geometric operations. geometric operations.
""" """
input_dataframe = input_dataframe.to_crs(tile.crs)
input_dataframe = geopandas.clip(input_dataframe, tile.geometry)
geometry = input_dataframe.unary_union geometry = input_dataframe.unary_union
geometry = TileProcessor.reproject_polygon(geometry, input_dataframe.crs, tile.crs)
if buffer_magnitude > 0.0: if buffer_magnitude > 0.0:
geometry = geometry.buffer(buffer_magnitude) geometry = geometry.buffer(buffer_magnitude)
geometry = TileProcessor.clip_to_tile_extent(geometry, tile) geometry = TileProcessor.clip_to_tile_extent(geometry, tile)
......
...@@ -38,7 +38,7 @@ setup( ...@@ -38,7 +38,7 @@ setup(
"rtree", "rtree",
"geopandas", "geopandas",
"rasterio", "rasterio",
"psycopg2", "psycopg2-binary",
"SQLAlchemy", "SQLAlchemy",
"GeoAlchemy2", "GeoAlchemy2",
"pyyaml", "pyyaml",
......
...@@ -81,14 +81,14 @@ def test_poligonize_array(): ...@@ -81,14 +81,14 @@ def test_poligonize_array():
expected_geometry = ( expected_geometry = (
"MULTIPOLYGON (((2549910 4629720, 2549940 4629720, " "MULTIPOLYGON (((2549910 4629720, 2549940 4629720, "
"2549970 4629720, 2549970 4629660, 2549940 4629660, " "2549970 4629720, 2549970 4629660, 2549940 4629660, "
"2549910 4629660, 2549910 4629720)), ((2549970 4629780, " "2549910 4629660, 2549910 4629720)), ((2549970 4629720, "
"2550000 4629780, 2550090 4629780, 2550090 4629810, " "2549970 4629780, 2550000 4629780, 2550090 4629780, "
"2550120 4629810, 2550120 4629750, 2550090 4629750, " "2550090 4629810, 2550120 4629810, 2550120 4629750, "
"2550090 4629720, 2550120 4629720, 2550120 4629660, " "2550090 4629750, 2550090 4629720, 2550120 4629720, "
"2550090 4629660, 2550090 4629630, 2550060 4629630, " "2550120 4629660, 2550090 4629660, 2550090 4629630, "
"2550060 4629660, 2550030 4629660, 2550030 4629690, " "2550060 4629630, 2550060 4629660, 2550030 4629660, "
"2550000 4629690, 2550000 4629720, 2549970 4629720, " "2550030 4629690, 2550000 4629690, 2550000 4629720, "
"2549970 4629780)))" "2549970 4629720)))"
) )
built_geometry = TileProcessor.polygonize_array( built_geometry = TileProcessor.polygonize_array(
...@@ -126,20 +126,24 @@ def test_clip_to_tile_extent(): ...@@ -126,20 +126,24 @@ def test_clip_to_tile_extent():
def test_process_dataframe_with_tile(): def test_process_dataframe_with_tile():
expected_geometry_roads = ( expected_geometry_roads = (
"POLYGON ((2550002.438602296 4629670.059528879, 2550002.454491734 " "POLYGON ((2550002.184577069 4629637.952911595, 2550002.438602296 "
"4629670.34505833, 2550007.486132718 4629718.894118963, 2550007.534455809 " "4629670.059528879, 2550002.454491734 4629670.34505833, 2550007.486132718 "
"4629719.202675823, 2550007.614596096 4629719.504536704, 2550020.082379065 " "4629718.894118963, 2550007.534455809 4629719.202675823, 2550007.614596096 "
"4629758.216188851, 2550020.178233149 4629758.472967537, 2550020.297122533 " "4629719.504536704, 2550020.082379065 4629758.216188851, 2550020.178233149 "
"4629758.719926265, 2550020.438054846 4629758.955003661, 2550020.599853719 " "4629758.472967537, 2550020.297122533 4629758.719926265, 2550020.438054846 "
"4629759.176237528, 2550020.781168612 4629759.381781219, 2550030.443700413 " "4629758.955003661, 2550020.599853719 4629759.176237528, 2550020.781168612 "
"4629769.375572084, 2550030.760692946 4629769.659947647, 2550049.072185669 " "4629759.381781219, 2550030.443700413 4629769.375572084, 2550030.760692946 "
"4629783.876796038, 2550053.931105311 4629790.803233128, 2550061.2602155 " "4629769.659947647, 2550049.072185669 4629783.876796038, 2550053.931105311 "
"4629790.803233128, 2550053.724702562 4629780.061286326, 2550053.541161971 " "4629790.803233128, 2550060.593091394 4629790.803233128, 2550060.594888479 "
"4629790.73518196, 2550060.573776196 4629790.441533886, 2550060.523983029 "
"4629790.151369173, 2550060.445988514 4629789.867482267, 2550060.340543782 "
"4629789.592607153, 2550060.208664322 4629789.329391029, 2550060.051620206 "
"4629789.08036881, 2550053.724702562 4629780.061286326, 2550053.541161971 "
"4629779.825551415, 2550053.335084511 4629779.609241042, 2550053.108513971 " "4629779.825551415, 2550053.335084511 4629779.609241042, 2550053.108513971 "
"4629779.41450048, 2550034.608849079 4629765.051557215, 2550025.57961757 " "4629779.41450048, 2550034.608849079 4629765.051557215, 2550025.57961757 "
"4629755.712777978, 2550013.42183824 4629717.963666889, 2550008.437281965 " "4629755.712777978, 2550013.42183824 4629717.963666889, 2550008.437281965 "
"4629669.86891498, 2550008.184577072 4629637.929176555, 2550002.184389279 " "4629669.86891498, 2550008.184577072 4629637.929176555, 2550002.185554927 "
"4629637.929176555, 2550002.438602296 4629670.059528879))" "4629637.929176555, 2550002.184577069 4629637.952911595))"
) )
roads_process = TileProcessor.process_dataframe_with_tile( roads_process = TileProcessor.process_dataframe_with_tile(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment