Skip to content

Commit

Permalink
累積問題(#21,#25,#26)のFix
Browse files Browse the repository at this point in the history
#21 県名None
#25 タイルのID変更
#26 Geoloniaスタイルへ変更
  • Loading branch information
takamotobiz committed Jan 19, 2021
1 parent d132f1a commit 0f9a586
Show file tree
Hide file tree
Showing 10 changed files with 4,204 additions and 98 deletions.
6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ RUN git clone https://github.com/mapbox/tippecanoe.git && \

RUN apt-get install -y gdal-bin

RUN pip3 install pyyaml

RUN pip3 install fiona

RUN pip3 install shapely
RUN pip3 install pyyaml fiona shapely

RUN mkdir /data

Expand Down
24 changes: 14 additions & 10 deletions GJWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ def __del__(self):

def setGeometry(self ,inGeom):
"""
Set "Geometry" notation.
Set "Geometry" member.
:param inGeom: Geometry data to output
:type inOutFile: Objects in Fiona Geometry
"""
self.Geometry = str(inGeom).replace("(","[").replace(")","]").replace("\'","\"")

def setProperty(self ,inName ,inValue):
"""
Set "Property" notation.
"Tippecanoe" is special notation for the tippecanoe utility.
Set "Property" member.
"Tippecanoe" is special member for the tippecanoe utility.
:param inName: Name of the property
:type inName: String
:param inValue: Value of the property
Expand All @@ -56,7 +56,7 @@ def setProperty(self ,inName ,inValue):

def setTippecanoe(self ,inName ,inValue):
"""
Set "Tippecanoe" notation.
Set "Tippecanoe" member.
"Tippecanoe" is an attribute of Feature object.
:param inName: Name of the tippecanoe
:type inName: String
Expand Down Expand Up @@ -84,20 +84,24 @@ def Write(self):
else:
self._jsonfd.write(",\n")

# Set "type" notation(Header for the Feature)
# Set "type" member(Header for the Feature)
self._jsonfd.write("\t{\"type\":\"Feature\",\n")
# Set "Geometry" notation
# Set "Geometry" member
self._jsonfd.write("\"geometry\":" + self.Geometry + ",\n")
# Set "Tippecanoe" notation
self._jsonfd.write("\"tippecanoe\":{" + self.Tippecanoe + "}")
# Set "Property" notation
# Set "Tippecanoe" member
if self.Tippecanoe != None:
self._jsonfd.write("\"tippecanoe\":{" + self.Tippecanoe + "},\n")
# Set "Property" member
if self.Properties != None:
self._jsonfd.write(",\n")
self._jsonfd.write("\"properties\":{" + self.Properties + "}")

# End of Feature
self._jsonfd.write("}")

# Clear all properties
self.Clear()

def Clear(self):
# Clear all properties
self.Geometry = None
self.Properties = None
Expand Down
19 changes: 19 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"options": {
"paths": {
"root": "",
"styles": "",
"mbtiles": ""
}
},
"styles": {
"oceanus": {
"style": "style.json"
}
},
"data": {
"oceanus": {
"mbtiles": "oceanus.mbtiles"
}
}
}
2 changes: 1 addition & 1 deletion ne2mbtiles
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ fi
cp /data/shp2geojson.yaml /app
python3 /app/shp2geojson.py
tippecanoe -z7 -f -o /data/oceanus.mbtiles /data/shp2geojson.json
sqlite3 /data/oceanus.mbtiles < /app/update.sql
#sqlite3 /data/oceanus.mbtiles < /app/update.sql
22 changes: 8 additions & 14 deletions runtilesv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,26 @@ while getopts ":d:p:n:h" OPT; do
echo "Usage: runtilesv.sh [options]"
echo "Options:"
echo " -n container name ( default "\""tilesv"\"" )"
echo " -p port number ( default 80 )"
echo " -p port number ( default 8080 )"
echo " -d directory for mbtiles ( default "\""/tmp"\"" )"
exit 1
;;
esac
done

if [ ! -e /data/config.json ]; then
echo "Deploy the files required for TileserverGL."
tar xvf ./tilesvenv.tar.gz -C $DIR
fi
if [ "$(docker container ls -q -f name=${CONTAINER_NAME})" ]; then
echo "Container ${CONTAINER_NAME} is running."
echo "Stop container ${CONTAINER_NAME}."
echo "Stop and remove container ${CONTAINER_NAME}."
docker container stop $CONTAINER_NAME
docker container rm $CONTAINER_NAME
fi
if [ "$(docker container ls -a -q -f name=${CONTAINER_NAME})" ]; then
echo "Container ${CONTAINER_NAME} already exist."
echo "Remove container ${CONTAINER_NAME}."
docker container rm $CONTAINER_NAME
fi
docker container rm $CONTAINER_NAME
if [ $PORTNO -ge 1 ]; then
docker run -d -it --name $CONTAINER_NAME -v $DIR:/data -p $PORTNO:80 klokantech/tileserver-gl
echo "docker run -d -it --name ${CONTAINER_NAME} -v ${DIR}:/data -p ${PORTNO}:80 klokantech/tileserver-gl"
else
docker run -d -it --name $CONTAINER_NAME -v $DIR:/data klokantech/tileserver-gl
echo "docker run -d -it --name ${CONTAINER_NAME} -v ${DIR}:/data -p ${PORTNO}:80 klokantech/tileserver-gl"
fi
cp ./config.json $DIR
mkdir $DIR/styles
cp ./style.json $DIR
docker run -d -it --name $CONTAINER_NAME -v $DIR:/data -p $PORTNO:8080 maptiler/tileserver-gl -c /data/config.json
echo "docker run -d -it --name ${CONTAINER_NAME} -v ${DIR}:/data -p ${PORTNO}:8080 maptiler/tileserver-gl -c /data/config.json"
32 changes: 20 additions & 12 deletions shp2geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,41 @@
# Get file information
for filename in layer['file']:
# Print start message
print('Start:['+str(dt.datetime.now())+']'+filename['name'])
print('Start:['+str(dt.datetime.now())+']'+filename['fname'])
# Open the shapefile
elements = fiona.open(basedir+filename['name'])
elements = fiona.open(basedir+filename['fname'])
# Get elements
for element in elements:
# Ignore Null Shapes
if element['geometry']==None:
continue
# Set "Property" notation
# Set "Property" member
if 'class' in filename:
gjWriter.setProperty('class' ,filename['class'])
if 'subclass' in filename:
gjWriter.setProperty('subclass' ,filename['subclass'])
if 'admin_level' in filename:
gjWriter.setProperty('admin_level' ,filename['admin_level'])
# Set "Tippecanoe" notation
if 'name' in filename:
if element['properties'][filename['name']]!=None:
# Set river name to property
gjWriter.setProperty('name' ,element['properties'][filename['name']])
# Set "Tippecanoe" member
gjWriter.setTippecanoe('layer' ,layer['layer'])
if 'minzoom' in filename:
gjWriter.setTippecanoe('minzoom' ,filename['minzoom'])
if 'maxzoom' in filename:
gjWriter.setTippecanoe('maxzoom' ,filename['maxzoom'])
# Set "Geometry" notation
# Set "Geometry" member
if 'attr' in filename:
# Attribute label (only polygon and multipolgon are supported)
# Issue#21(Do not mark "None" on the map)
if element['properties'][filename['attr']]==None:
gjWriter.Clear()
continue
# Attribute label (only polygon and multipolygon are supported)
if element['geometry']['type']=='MultiPolygon' or element['geometry']['type']=='Polygon':
# Get attribute name and set "Property" notation
gjWriter.setProperty('name:en' ,element['properties'][filename['attr']])
# Get attribute name and set "Property" member
gjWriter.setProperty('name' ,element['properties'][filename['attr']])
area=0.0
# Get polygon
for parts in element['geometry']['coordinates']:
Expand All @@ -72,18 +80,18 @@
geometry = "{\"type\":\"Point\",\"coordinates\":"
geometry += str(maxpgn.centroid).replace("(","[").replace(")","]").replace("\'","\"").replace("POINT " ,"").replace(" " ,",")
geometry += "}"
# Set "Geometry" notation
# Set "Geometry" member
gjWriter.setGeometry(geometry)
else:
# Write "Geometry" notation(Other than attribute label)
# Write "Geometry" member(Other than attribute label)
gjWriter.setGeometry(element['geometry'])
# Write "Geometry" notation
# Write "Geometry" member
gjWriter.Write()

# Close Shapefile
elements.close()
# Print end message
print('End :['+str(dt.datetime.now())+']'+filename['name'])
print('End :['+str(dt.datetime.now())+']'+filename['fname'])

# Dispose GJWriter instance
del gjWriter
96 changes: 41 additions & 55 deletions shp2geojson.yaml
Original file line number Diff line number Diff line change
@@ -1,124 +1,110 @@
version: 0.2
version: 0.9
basedir: /data/
outputfile: /data/shp2geojson.json
layers:

- layer: landuse
file:
- name: 50m_cultural/ne_50m_urban_areas.shp
class: residential
- fname: 50m_cultural/ne_50m_urban_areas.shp
class: commercial
minzoom: 4
maxzoom: 4
- name: 50m_cultural/ne_50m_urban_areas.shp
class: residential
minzoom: 5
maxzoom: 7

- layer: landcover
file:
- name: 110m_physical/ne_110m_glaciated_areas.shp
class: ice
subclass: glacier
minzoom: 0
maxzoom: 1
- name: 50m_physical/ne_50m_glaciated_areas.shp
class: ice
subclass: glacier
minzoom: 2
maxzoom: 4
- name: 50m_physical/ne_50m_antarctic_ice_shelves_polys.shp
class: ice
subclass: ice_shelf
minzoom: 2
maxzoom: 4
- name: 10m_physical/ne_10m_glaciated_areas.shp
class: ice
subclass: glacier
minzoom: 5
maxzoom: 7
- name: 10m_physical/ne_10m_antarctic_ice_shelves_polys.shp
class: ice
subclass: ice_shelf
- fname: 10m_cultural/ne_10m_urban_areas.shp
class: commercial
minzoom: 5
maxzoom: 7

- layer: water
file:
- name: 110m_physical/ne_110m_ocean.shp
- fname: 110m_physical/ne_110m_ocean.shp
class: ocean
minzoom: 0
maxzoom: 1
- name: 50m_physical/ne_50m_ocean.shp
- fname: 50m_physical/ne_50m_ocean.shp
class: ocean
minzoom: 2
maxzoom: 4
- name: 10m_physical/ne_10m_ocean.shp
- fname: 10m_physical/ne_10m_ocean.shp
class: ocean
minzoom: 5
maxzoom: 7
- name: 110m_physical/ne_110m_lakes.shp
- fname: 110m_physical/ne_110m_lakes.shp
class: lakes
minzoom: 0
maxzoom: 1
- name: 50m_physical/ne_50m_lakes.shp
- fname: 50m_physical/ne_50m_lakes.shp
class: lakes
minzoom: 2
maxzoom: 4
- name: 10m_physical/ne_10m_lakes.shp
- fname: 10m_physical/ne_10m_lakes.shp
class: lakes
minzoom: 5
maxzoom: 7

- layer: water_name
file:
- name: 10m_physical/ne_10m_geography_marine_polys.shp
- fname: 110m_physical/ne_110m_geography_marine_polys.shp
class: ocean
attr: name_ja
minzoom: 0
maxzoom: 1
- fname: 50m_physical/ne_50m_geography_marine_polys.shp
class: ocean
attr: name_ja
minzoom: 2
maxzoom: 4
- fname: 10m_physical/ne_10m_geography_marine_polys.shp
class: ocean
attr: name_ja
minzoom: 5
maxzoom: 7

- layer: water_way
- layer: waterway
file:
- name: 110m_physical/ne_110m_rivers_lake_centerlines.shp
class: ocean
- fname: 110m_physical/ne_110m_rivers_lake_centerlines.shp
class: river
name: name_ja
minzoom: 3
maxzoom: 3
- name: 50m_physical/ne_50m_rivers_lake_centerlines.shp
class: ocean
- fname: 50m_physical/ne_50m_rivers_lake_centerlines.shp
class: river
name: name_ja
minzoom: 4
maxzoom: 5
- name: 10m_physical/ne_10m_rivers_lake_centerlines.shp
class: ocean
- fname: 10m_physical/ne_10m_rivers_lake_centerlines.shp
class: river
name: name_ja
minzoom: 6
maxzoom: 7

- layer: boundary
file:
- name: 110m_cultural/ne_110m_admin_0_boundary_lines_land.shp
- fname: 110m_cultural/ne_110m_admin_0_boundary_lines_land.shp
admin_level: 2
minzoom: 0
maxzoom: 0
- name: 50m_cultural/ne_50m_admin_0_boundary_lines_land.shp
- fname: 50m_cultural/ne_50m_admin_0_boundary_lines_land.shp
admin_level: 4
minzoom: 0
maxzoom: 7
- name: 10m_cultural/ne_10m_admin_0_boundary_lines_land.shp
- fname: 10m_cultural/ne_10m_admin_0_boundary_lines_land.shp
admin_level: 2
minzoom: 3
maxzoom: 7
- name: 10m_cultural/ne_10m_admin_1_states_provinces_lines.shp
- fname: 10m_cultural/ne_10m_admin_1_states_provinces_lines.shp
admin_level: 4
minzoom: 5
maxzoom: 7

- layer: place
file:
- name: 110m_cultural/ne_110m_admin_0_countries.shp
class: country
- fname: 110m_cultural/ne_110m_admin_0_countries.shp
class: town
attr: NAME_JA
minzoom: 0
maxzoom: 6
- name: 10m_cultural/ne_10m_admin_1_states_provinces.shp
class: city
- fname: 10m_cultural/ne_10m_admin_1_states_provinces.shp
class: town
attr: name_ja
minzoom: 5
maxzoom: 7
Loading

0 comments on commit 0f9a586

Please sign in to comment.