import sys
import json
import csv
import shapely.wkb
import shapely.geometry
import shapely.ops
import codecs
import os
import inspect
import copy
from osgeo import ogr
from osgeo import osr
from booleano.parser import Grammar, EvaluableParseManager, SymbolTable, Bind
from booleano.operations import Variable
class Map:
def __init__(self, name, language):
self.paths = {}
self.name = name
self.language = language
self.width = 0
self.height = 0
self.bbox = []
def addPath(self, path, code, name):
self.paths[code] = {"path": path, "name": name}
def getJSCode(self):
map = {"paths": self.paths, "width": self.width, "height": self.height, "insets": self.insets, "projection": self.projection}
return "jQuery.fn.vectorMap('addMap', '"+self.name+"_"+self.projection['type']+"',"+json.dumps(map)+');'
class Converter:
def __init__(self, config):
args = {
'buffer_distance': -0.4,
'simplify_tolerance': 0.2,
'longitude0': 0,
'projection': 'mill',
'name': 'world',
'width': 900,
'left': 0,
'top': 0,
'language': 'en',
'precision': 2,
'insets': []
}
args.update(config)
self.config = args
self.map = Map(args['name'], args.get('language'))
if args.get('sources'):
self.sources = args['sources']
else:
self.sources = [{
'input_file': args.get('input_file'),
'where': args.get('where'),
'name_field': args.get('name_field'),
'code_field': args.get('code_field'),
'input_file_encoding': args.get('input_file_encoding')
}]
default_source = {
'where': '',
'name_field': 0,
'code_field': 1,
'input_file_encoding': 'iso-8859-1'
}
for index in range(len(self.sources)):
for key in default_source:
if self.sources[index].get(key) is None:
self.sources[index][key] = default_source[key]
self.features = {}
self.width = args.get('width')
self.left = args.get('left')
self.top = args.get('top')
self.minimal_area = args.get('minimal_area')
self.longitude0 = float(args.get('longitude0'))
self.projection = args.get('projection')
self.precision = args.get('precision')
self.buffer_distance = args.get('buffer_distance')
self.simplify_tolerance = args.get('simplify_tolerance')
self.for_each = args.get('for_each')
self.emulate_longitude0 = args.get('emulate_longitude0')
if args.get('emulate_longitude0') is None and (self.projection == 'merc' or self.projection =='mill') and self.longitude0 != 0:
self.emulate_longitude0 = True
if args.get('viewport'):
self.viewport = map(lambda s: float(s), args.get('viewport').split(' '))
else:
self.viewport = False
# spatial reference to convert to
self.spatialRef = osr.SpatialReference()
projString = '+proj='+str(self.projection)+' +a=6381372 +b=6381372 +lat_0=0'
if not self.emulate_longitude0:
projString += ' +lon_0='+str(self.longitude0)
self.spatialRef.ImportFromProj4(projString)
# handle map insets
if args.get('insets'):
self.insets = args.get('insets')
else:
self.insets = []
def convert(self, data_source, output_file):
codes = map(lambda g: g.properties[self.config['code_field']], data_source.geometries)
main_codes = copy.copy(codes)
self.map.insets = []
envelope = []
for inset in self.insets:
insetBbox = self.renderMapInset(data_source, inset['codes'], inset['left'], inset['top'], inset['width'])
insetHeight = (insetBbox[3] - insetBbox[1]) * (inset['width'] / (insetBbox[2] - insetBbox[0]))
self.map.insets.append({
"bbox": [{"x": insetBbox[0], "y": -insetBbox[3]}, {"x": insetBbox[2], "y": -insetBbox[1]}],
"left": inset['left'],
"top": inset['top'],
"width": inset['width'],
"height": insetHeight
})
envelope.append(
shapely.geometry.box(
inset['left'], inset['top'], inset['left'] + inset['width'], inset['top'] + insetHeight
)
)
for code in inset['codes']:
main_codes.remove(code)
insetBbox = self.renderMapInset(data_source, main_codes, self.left, self.top, self.width)
insetHeight = (insetBbox[3] - insetBbox[1]) * (self.width / (insetBbox[2] - insetBbox[0]))
envelope.append( shapely.geometry.box( self.left, self.top, self.left + self.width, self.top + insetHeight ) )
mapBbox = shapely.geometry.MultiPolygon( envelope ).bounds
self.map.width = mapBbox[2] + mapBbox[0]
self.map.height = mapBbox[3] + mapBbox[1]
self.map.insets.append({
"bbox": [{"x": insetBbox[0], "y": -insetBbox[3]}, {"x": insetBbox[2], "y": -insetBbox[1]}],
"left": self.left,
"top": self.top,
"width": self.width,
"height": insetHeight
})
self.map.projection = {"type": self.projection, "centralMeridian": float(self.longitude0)}
open(output_file, 'w').write( self.map.getJSCode() )
if self.for_each is not None:
for code in codes:
childConfig = copy.deepcopy(self.for_each)
for param in ('input_file', 'output_file', 'where', 'name'):
childConfig[param] = childConfig[param].replace('{{code}}', code.lower())
converter = Converter(childConfig)
converter.convert(childConfig['output_file'])
def renderMapInset(self, data_source, codes, left, top, width):
envelope = []
geometries = filter(lambda g: g.properties[self.config['code_field']] in codes, data_source.geometries)
for geometry in geometries:
envelope.append( geometry.geom.envelope )
bbox = shapely.geometry.MultiPolygon( envelope ).bounds
scale = (bbox[2]-bbox[0]) / width
# generate SVG paths
for geometry in geometries:
geom = geometry.geom
if self.buffer_distance:
geom = geom.buffer(self.buffer_distance*scale, 1)
if geom.is_empty:
continue
if self.simplify_tolerance:
geom = geom.simplify(self.simplify_tolerance*scale, preserve_topology=True)
if isinstance(geom, shapely.geometry.multipolygon.MultiPolygon):
polygons = geom.geoms
else:
polygons = [geom]
path = ''
for polygon in polygons:
rings = []
rings.append(polygon.exterior)
rings.extend(polygon.interiors)
for ring in rings:
for pointIndex in range( len(ring.coords) ):
point = ring.coords[pointIndex]
if pointIndex == 0:
path += 'M'+str( round( (point[0]-bbox[0]) / scale + left, self.precision) )
path += ','+str( round( (bbox[3] - point[1]) / scale + top, self.precision) )
else:
path += 'l' + str( round(point[0]/scale - ring.coords[pointIndex-1][0]/scale, self.precision) )
path += ',' + str( round(ring.coords[pointIndex-1][1]/scale - point[1]/scale, self.precision) )
path += 'Z'
self.map.addPath(path, geometry.properties[self.config['code_field']], geometry.properties[self.config['name_field']])
return bbox
class Geometry:
def __init__(self, geometry, properties):
self.geom = geometry
self.properties = properties
class GeometryProperty(Variable):
operations = set(["equality", "membership"])
def __init__(self, name):
self.name = name
def equals(self, value, context):
return context[self.name] == value
def belongs_to(self, value, context):
return value in context[self.name]
def is_subset(self, value, context):
return set(value).issubset(set(context[self.name]))
def to_python(self, value):
return unicode(value[self.name])
class DataSource:
def __init__(self, config):
default_config = {
"projection": "merc",
"longitude0": 0
}
default_config.update(config)
self.config = default_config
self.spatialRef = osr.SpatialReference()
projString = '+proj='+str(self.config['projection'])+' +a=6381372 +b=638
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
2023全新SF授权系统源码 V3.7全开源无加密版本 (3662个子文件)
icons.css 707KB
argon.css 467KB
argon.min.css 338KB
bootstrap.css 188KB
style.css 170KB
bootstrap.min.css 152KB
bootstrap.min.css 139KB
bootstrap.min.css 137KB
vendor.css 134KB
bootstrap.min.css 124KB
bootstrap.min.css 120KB
bootstrap.min.css 106KB
style.min.css 105KB
admin.css 96KB
materialdesignicons.min.css 85KB
style.css 80KB
layui.css 73KB
animate.css 71KB
layui.css 68KB
bootstrap-grid.css 62KB
notice.css 61KB
all.min.css 58KB
animate.min.css 57KB
all.min.css 54KB
skin.min.css 54KB
skin.min.css 54KB
fontawesome.min.css 52KB
all.min.css 50KB
bootstrap-grid.min.css 47KB
components.css 41KB
hui.css 40KB
bootstrap-grid.min.css 38KB
components.css 33KB
style.css 31KB
admin.css 31KB
style.css 29KB
iziToast.min.css 29KB
main.css 28KB
bootstrap-social.css 27KB
sweetalert2.min.css 26KB
v4-shims.min.css 26KB
admim.css 26KB
admin.css 26KB
quill.bubble.css 25KB
quill.snow.css 24KB
core.css 23KB
jquery.scrollbar.css 23KB
bootstrap-datepicker3.standalone.min.css 21KB
bootstrap-datepicker3.min.css 21KB
skin.mobile.min.css 21KB
skin.mobile.min.css 21KB
content.min.css 17KB
content.inline.min.css 17KB
content.inline.min.css 17KB
content.min.css 17KB
responsive.css 16KB
bootstrap-datepicker.standalone.min.css 16KB
fullcalendar.min.css 16KB
bootstrap-datepicker.min.css 15KB
layim.css 15KB
summernote-bs4.css 15KB
select2.min.css 15KB
layer.css 14KB
layer.css 14KB
main.min.css 14KB
dropzone.css 12KB
introJs.css 12KB
template.css 12KB
template.css 12KB
dropdown.css 11KB
main.css 10KB
jquery.lavalamp.css 10KB
layui.mobile.css 10KB
layui.mobile.css 10KB
dropzone.min.css 9KB
quill.core.css 9KB
nucleo.css 9KB
layim.css 9KB
main.css 7KB
laydate.css 7KB
laydate.css 7KB
steps.css 7KB
metroStyle.css 7KB
jquery-jvectormap.css 6KB
zTreeStyle.css 6KB
wechat_pay.css 6KB
userPay.css 5KB
Cropper.css 5KB
dataTables.bootstrap4.min.css 5KB
bootstrap-reboot.css 5KB
prism-previewers.css 5KB
svg-with-js.min.css 5KB
cascader.css 5KB
iconfont.css 5KB
buttons.bootstrap4.min.css 4KB
prism-coy.css 4KB
select.bootstrap4.min.css 4KB
prism-twilight.css 4KB
header.css 4KB
bootstrap-reboot.min.css 4KB
共 3662 条
- 1
- 2
- 3
- 4
- 5
- 6
- 37
资源评论
普通网友
- 粉丝: 2785
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功