Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesca-Fissore committed Jan 8, 2019
0 parents commit 47a0629
Show file tree
Hide file tree
Showing 17 changed files with 1,556 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.idea/
.ipynb_checkpoints/
ENV/
*.egg-info/
*.pyc
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
shp2city is a software able to convert cartographic data, containing building information, from ESRI shapefile format to 3D CityGML model.
It supports in input one or multiple ESRI shapefile that used to generate a cityGML file.
In order to perform the conversion process, several parameters should be set by user.
Specifically, the following are requested:
(1) the name of output CityGML file
(2) a spatial relationship parameter, chosen between: “intersects”, “within” or “contains”
(3) paths of inputs files.

The first parameter will be used in the final step in order to save the 3d model.
The second parameter is a fundamental request in order to perform spatial join between multiple files. The choice of this parameter is restricted to three possibilities: i) intersects, ii) contains, iii) within
As for the remaining parameter, it can be composed of paths to one or two shapefiles.
In case there is only one input file, the spatial join step is skipped and the CityGML file will be processed from the single input file purge from null geometries.
In presence of two files, the spatial join process can be performed according to the spatial relation specified as input parameter.

##Installation of the command-line tool
For unix os:
$ pip install shp2city

To see all the options possible:

$ shp2city --help



43 changes: 43 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# shp2city: program to convert shapefile to cityGML
# Copyright (C) 2018-2019 Francesca Fissore <[email protected]>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


from setuptools import setup, find_packages

setup(
name='shp2city',
version='0.1.0',
description='Convert shapefile into cityGML',
#url='https://github.com/pypa/sampleproject', # Optional
author='Francesca Fissore',
author_email='[email protected]',
packages=find_packages(),
install_requires=[
'geopandas',
'lxml',
'numpy',
'pick',
'rtree'
],
tests_require = [
'pytest',
],
entry_points={
'console_scripts': [
'shp2city=shp2city.main:main',
],
},
)
Empty file added shp2city/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions shp2city/buildings_inits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# shp2city: program to convert shapefile to cityGML
# Copyright (C) 2018-2019 Francesca Fissore <[email protected]>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

def buildings_inits(content, list_attributes, list_fields):
inits = {}
for attribute, field in zip(list_attributes, list_fields):
if field != 'NA':
inits[attribute] = str(content[field])
else:
inits[attribute] = ''
return inits
37 changes: 37 additions & 0 deletions shp2city/explode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# shp2city: program to convert shapefile to cityGML
# Copyright (C) 2018-2019 Francesca Fissore <[email protected]>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import geopandas as gpd
from shapely.geometry.polygon import Polygon
from shapely.geometry.multipolygon import MultiPolygon

def explode(indf):
#indf = gpd.GeoDataFrame.from_file(indata)
outdf = gpd.GeoDataFrame(columns=indf.columns)

for idx, row in indf.iterrows():
#print row.geometry.type
if row.geometry.type == 'Polygon':
outdf = outdf.append(row,ignore_index=True)
if row.geometry.type == 'MultiPolygon':
multdf = gpd.GeoDataFrame(columns=indf.columns)
recs = len(row.geometry)
multdf = multdf.append([row]*recs,ignore_index=True)
for geom in range(recs):
multdf.loc[geom,'geometry'] = row.geometry[geom]
outdf = outdf.append(multdf,ignore_index=True)

return outdf
1 change: 1 addition & 0 deletions shp2city/gml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from writer import write
94 changes: 94 additions & 0 deletions shp2city/gml/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# shp2city: program to convert shapefile to cityGML
# Copyright (C) 2018-2019 Francesca Fissore <[email protected]>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from lxml import etree


namespaces = {
None: "http://www.opengis.net/citygml/2.0",
# "app": "http://www.opengis.net/citygml/appearance/2.0",
# "bldg": "http://www.opengis.net/citygml/building/2.0",
# "dem": "http://www.opengis.net/citygml/relief/2.0",
# "frn": "http://www.opengis.net/citygml/cityfurniture/2.0",
"gen": "http://www.opengis.net/citygml/generics/2.0",
"gml": "http://www.opengis.net/gml",
# "grp": "http://www.opengis.net/citygml/cityobjectgroup/2.0",
# "luse": "http://www.opengis.net/citygml/landuse/2.0",
# "pfx0": "http://www.citygml.org/citygml/profiles/base/2.0",
# "veg": "http://www.opengis.net/citygml/vegetation/2.0",
# "tex": "http://www.opengis.net/citygml/texturedsurface/2.0",
# "tran": "http://www.opengis.net/citygml/transportation/2.0",
# "wtr": "http://www.opengis.net/citygml/waterbody/2.0",
# "xAL": "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0",
# "xlink": "http://www.w3.org/1999/xlink",
# "xsi": "http://www.w3.org/2001/XMLSchema-instance",
# "sch": "http://www.ascc.net/xml/schematron",
# "smil20": "http://www.w3.org/2001/SMIL20/",
# "smil20lang": "http://www.w3.org/2001/SMIL20/Language",
}


# def root(parent, no_namespaces=False):
# nsmap = None if no_namespaces else namespaces
# return parent.element("CityModel", nsmap=nsmap)

def root(no_namespaces=False):
nsmap = None if no_namespaces else namespaces
return etree.Element("CityModel", nsmap=nsmap)

def root2(xf, no_namespaces=False):
nsmap = None if no_namespaces else namespaces
return xf.element("CityModel", nsmap=nsmap)

def element(element_name, parent=None, attributes=None, **kwargs):
if attributes is None:
attributes = kwargs
else:
attributes.update(kwargs)
attributes = {qualify_name(k): v for k, v in attributes.items()}

if parent is None:
return etree.Element(qualify_name(element_name, always=True), **attributes)
else:
return etree.SubElement(parent, qualify_name(element_name, always=True), **attributes)

def qualify_name(name, always=False):
idx = name.find(':')
if idx < 0:
ns = None
else:
ns = name[:idx]
name = name[idx+1:]

if ns is None and always == False:
return name
else:
urn = namespaces[ns]
return '{%s}%s' % (urn, name)


def identifier_format(identifier):
if isinstance(identifier,unicode):
pass
else:
pass#identifier = unicode(hex(identifier))
identifier= str(identifier)
if identifier.startswith('RLB'):
pass
else:
identifier = unicode('RLB-'+ str(identifier))

return identifier
Loading

0 comments on commit 47a0629

Please sign in to comment.