def results(self): results_list = [] one_zipfile_contents = [] for theme in self.feature_selection.themes: for geom_type in self.feature_selection.geom_types(theme): basename = os.path.join(self.output_dir, slugify(theme) + "_" + geom_type) if os.path.isfile(basename + ".shp"): shpset = [ basename + ".shp", basename + ".cpg", basename + ".dbf", basename + ".prj", basename + ".shx", ] if self.per_theme: results_list.append( Artifact(shpset, Shapefile.name, theme=theme, basename=basename + ".shp")) else: one_zipfile_contents = one_zipfile_contents + shpset if not self.per_theme: results_list.append( Artifact(one_zipfile_contents, Shapefile.name, basename="shp")) return results_list
def results(self): if self.per_theme: results_list = [] for theme in self.feature_selection.themes: results_list.append( Artifact([ os.path.join(self.stage_dir, slugify(theme)) + ".gpkg" ], Geopackage.name, theme=theme)) return results_list else: return [Artifact([self.output_gpkg], Geopackage.name)]
def datasets(self): # noqa if self._datasets: return self._datasets self._datasets = {} for theme in self._feature_selection.themes: dataset = Dataset() name = u'{}_{}'.format(self._dataset_prefix, slugify(theme)) title = u'{} {} (OpenStreetMap Export)'.format(self._name, theme) tags = [] caveats = '' if 'hdx' in self._feature_selection.doc[theme]: hdx = self._feature_selection.doc[theme]['hdx'] caveats = hdx.get('caveats', caveats) if 'tags' in hdx: tags = map(lambda tag: tag.strip(), hdx['tags'].split(',')) dataset['name'] = name dataset['title'] = title dataset['caveats'] = caveats dataset['private'] = self.is_private dataset['notes'] = self.hdx_note(theme) dataset['dataset_source'] = 'OpenStreetMap contributors' dataset['owner_org'] = '225b9f7d-e7cb-4156-96a6-44c9c58d31e3' dataset['maintainer'] = 'osm2hdx' dataset['license_id'] = self._license dataset['methodology'] = 'Other' dataset['methodology_other'] = 'Volunteered geographic information' dataset['data_update_frequency'] = str(self._data_update_frequency) dataset['subnational'] = str(int(self.subnational)) dataset['groups'] = [] # warning: this makes a network call [dataset.add_other_location(x) for x in self._locations] dataset.add_tags(tags) #ga = GalleryItem({ # 'title': 'OSM Analytics', # 'description': 'View detailed information about OpenStreetMap edit history in this area.', # 'url': self.osm_analytics_url, # 'image_url': 'http://{}/static/ui/images/osm_analytics.png'.format(self.hostname), # 'type': 'Visualization', #}) #dataset.add_update_galleryitem(ga) self._datasets[theme] = dataset return self._datasets
def results(self): results_list = [] one_zipfile_contents = [] for theme in self.feature_selection.themes: for geom_type in self.feature_selection.geom_types(theme): basename = os.path.join( self.output_dir, slugify(theme) + "_" + geom_type) + ".kml" if self.per_theme: results_list.append( Artifact([basename], KML.name, theme=theme)) else: one_zipfile_contents.append(basename) if not self.per_theme: results_list.append( Artifact(one_zipfile_contents, KML.name, basename="kml")) return results_list
def run(self): """ Create the GeoPackage from the osm data. """ if self.is_complete: LOG.debug("Skipping Geopackage, file exists") return keys_points = self.feature_selection.key_union('points') keys_lines = self.feature_selection.key_union('lines') keys_polygons = self.feature_selection.key_union('polygons') osmconf = OSMConfig(self.stage_dir, points=keys_points, lines=keys_lines, polygons=keys_polygons) conf = osmconf.create_osm_conf() ogr_cmd = self.ogr_cmd.safe_substitute({ 'gpkg': self.output_gpkg, 'osm': self.input_pbf, 'osmconf': conf }) LOG.debug('Running: %s' % ogr_cmd) subprocess.check_call(ogr_cmd, shell=True, executable='/bin/bash') """ Create the default osm gpkg schema """ conn = sqlite3.connect(self.output_gpkg) conn.enable_load_extension(True) cur = conn.cursor() cur.execute("select load_extension('mod_spatialite')") cur.execute( "CREATE TABLE boundary (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, geom GEOMETRY)" ) cur.execute( "INSERT INTO boundary (geom) VALUES (GeomFromWKB(?,4326));", (self.aoi_geom.wkb, )) cur.executescript(SPATIAL_SQL) self.update_zindexes(cur, self.feature_selection) # add themes create_sqls, index_sqls = self.feature_selection.sqls for query in create_sqls: cur.executescript(query) for query in index_sqls: cur.executescript(query) conn.commit() conn.close() if self.per_theme: # this creates per-theme GPKGs for theme in self.feature_selection.themes: conn = sqlite3.connect(self.stage_dir + slugify(theme) + ".gpkg") conn.enable_load_extension(True) cur = conn.cursor() cur.execute("attach database ? as 'geopackage'", (self.output_gpkg, )) cur.execute( "create table gpkg_spatial_ref_sys as select * from geopackage.gpkg_spatial_ref_sys" ) cur.execute( "create table gpkg_contents as select * from geopackage.gpkg_contents where 0" ) cur.execute( "create table gpkg_geometry_columns as select * from geopackage.gpkg_geometry_columns where 0" ) for geom_type in self.feature_selection.geom_types(theme): for stmt in self.feature_selection.create_sql( theme, geom_type): cur.executescript(stmt) conn.commit() conn.close()