这个你d3.js数据里面去找,下面这个网站去下载,
或者你可以下载SHP文件,参考这个人的
===========================
此外MySQL57 里面有 ST_AsGeoJSON
===========================分割线====================================
# this is a file to decode the shape file into the geojson
# a.shape file consists of a.shp ,a.prj,a.shx,a.dbf
# .shp file header struct
# ---------------------------
# 1.Big Integer 4 byte
# 2.Little Integer 4 byte
# 3.Little Double 8 byte
# ---------------------------
# typedef struct header{
# UNDEFINED 7 Big Integers 28byte
# Version 1 Little Integers 4byte
# ShapeType 1 Little Integers 4byte
# EXTENT 4 Little Double 32byte
# 3D-PROPS 4 Little Double 32byte
# }
#
#
import struct
import json
def readShp(filepath):
features = []
bbox=[]
featurecollections = {"type": "FeatureCollection", "features": features}
with open(filepath, 'rb') as f:
unused = unpack('>iiiiiii', f.read(4 * 7))
version, = unpack('
shapeType, = unpack('
xmin, ymin, xmax, ymax = unpack('
bbox=[xmin,ymin,xmax,ymax]
featurecollections["bbox"]=bbox
extensions = unpack('
# print(unused,"version=",version,shapeType,xmin,ymin,xmax,ymax)
# (9994, 0, 0, 0, 0, 0, 1114) version= (1000,) (1,) -4480198.5 1433525.79887 24615124.978985116 6502586.830347195
# header end here
#
# begin read records
# a record consist of header,content
# header
# ---------------
# serial Big Integer 4byte
# length Big Integer 4byte the length of the following record ,and units is 2 byte length*2-4(shapetype)
# shapetype Litte Integer 4byte
# POINT:[serial][length][shapetype][lat][lnt]
# Little Double 4yte Little Integer Little integer Little Integer * #lines Little Double 2*#vertexes
# LINE:[extent:xmin,ymin,xmax,ymax][#lines or #ploygons][ #vertexes ][#start index of each polyline or polygon][ vertexes list ]
#
# Polygon:like above
while True:
try:
# point
if shapeType == 1:
serial, length = unpack('>ii', f.read(4 + 4))
shpType, = unpack('
x, y = unpack('
print(x, y)
geos = {
'type': "Point",
"coordinates": [x, y]
}
feature = {
"type": "Feature",
"geometry": geos,
"properties": {}
}
# print(feature)
features.append(feature)
elif shapeType==3:
serial, length = unpack('>ii', f.read(4 + 4))
shpType, = unpack('
xmin, ymin, xmax, ymax = unpack('
FeatureBBOX=[xmin,ymin,xmax,ymax]
nums_of_lines, nums_of_vertexes = unpack('
start_index = [unpack('
vertexes = [list(unpack('
if nums_of_lines==1:
#convert to LineString
geos={
"type":"LineString",
"coordinates":vertexes
}
feature = {
"type": "Feature",
"bbox":FeatureBBOX,
"geometry": geos,
"properties": {}
}
else:
lines=[[] for i in range(0,nums_of_lines)]
for i in range(0,nums_of_lines-1):
lines[i]=vertexes[start_index[i]:start_index[i+1]]
lines[nums_of_lines-1]=vertexes[start_index[nums_of_lines-1]:]
geos={
"type":"MultiLineString",
"coordinates":lines
}
feature = {
"type": "Feature",
"geometry": geos,
"properties": {}
}
features.append(feature)
elif shapeType==5:
serial, length = unpack('>ii', f.read(4 + 4))
shpType, = unpack('
xmin, ymin, xmax, ymax = unpack('
nums_of_lines, nums_of_vertexes = unpack('
start_index = [unpack('
vertexes = [list(unpack('
if nums_of_lines==1:
#convert to LineString
#hi,why reverse,well that's shp record the point clockwise,but geojson new spec requires right-hand rule
#https://gis.stackexchange.com/questions/119150/order-of-polygon-vertices-in-general-gis-clockwise-or-counterclockwise
vertexes.reverse()
geos={
"type":"Polygon",
"coordinates":[vertexes]
}
feature = {
"type": "Feature",
"geometry": geos,
"properties": {}
}
else:
lines=[[] for i in range(0,nums_of_lines)]
for i in range(0,nums_of_lines-1):
lines[i]=vertexes[start_index[i]:start_index[i+1]]
#to follow the counter-clockwise rule or right-hand rule
lines[i].reverse()
lines[nums_of_lines-1]=vertexes[start_index[nums_of_lines-1]:]
geos={
"type":"MultiPolygon",
"coordinates":[lines]
}
feature = {
"type": "Feature",
"geometry": geos,
"properties": {}
}
features.append(feature)
except struct.error as e:
#there is a end of file,it's not so nice
break
f.close()
return featurecollections
if __name__ == "__main__":
filepath="Anhui.shp"
from struct import *
with open('test.json','w') as f:
f.write(json.dumps(readShp(filepath)))
——————————————————————————————
这是我写的一个python读shp文件转换成geojson文件的代码,没有第三方的。
直接可以下到县级别的,然后用这个python转换一下,基本都是polygon,缺点就是属性数据我没读,到底来说,还是在postgis中转最好,postgis用的是gdal的,所以安装gdal也可以的。
有时间再写读dbf的。