(转)WKT转换工具terraformers
http://blog.csdn.net/gisshixisheng/article/details/53150111
概述:
前面的文章中,提到了Arcgis中实现wkt转换为geometry,但是这种转换仅实现了简单的点(point)、线(polyline)和面(polygon)的转换,对于复杂点或者复杂多边形没有涉及,在本文讲述通过terraformers加载展示wkt。
terraformers简介:
terraformers是Esri的一个开源项目,主要功能如下:
大家可通过http://download.csdn.NET/detail/gisshixisheng/9681608下载相关的js文件,也可直接在github上下载,github上的地址为https://github.com/Esri/Terraformer。
实现代码:
1、Arcgis加载WKT
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
- <title>Hello Map</title>
- <link rel="stylesheet" href="http://localhost/arcgis_js_311/api/arcgis_js_api/library/3.11/3.11/dijit/themes/tundra/tundra.css">
- <link rel="stylesheet" href="http://localhost/arcgis_js_311/api/arcgis_js_api/library/3.11/3.11/esri/css/esri.css"><style>
- html, body, #map {
- height: 100%;
- width: 100%;
- margin: 0;
- padding: 0;
- }
- </style>
- <script src="../../plugin/terraformer/terraformer.js"></script>
- <script src="../../plugin/terraformer/terraformer-wkt-parser.js"></script>
- <script src="../../plugin/terraformer/terraformer-arcgis-parser.js"></script>
- <script src="http://localhost/arcgis_js_311/api/arcgis_js_api/library/3.11/3.11/init.js"></script>
- <script src="../../plugin/jquery/jquery-1.8.3.js"></script>
- <script>
- var map;
- require([ "esri/map",
- "esri/layers/ArcGISTiledMapServiceLayer",
- "esri/layers/GraphicsLayer",
- "esri/graphic",
- "esri/geometry/Point",
- "esri/geometry/jsonUtils",
- "esri/symbols/SimpleMarkerSymbol",
- "esri/symbols/SimpleLineSymbol",
- "esri/symbols/SimpleFillSymbol",
- "esri/Color",
- "dojo/domReady!"
- ],
- function(Map,
- Tiled,
- GraphicsLayer,
- Graphic,
- Point,
- geometryJsonUtils,
- SimpleMarkerSymbol,
- SimpleLineSymbol,
- SimpleFillSymbol,
- Color){
- map = new Map("map");
- var tiled = new Tiled("http://localhost:6080/arcgis/rest/services/lzugis/base_china/MapServer");
- map.addLayer(tiled);
- var mapCenter = new Point(103.847, 36.0473, {"wkid":4326});
- map.centerAndZoom(mapCenter,1);
- var gLayer = new GraphicsLayer();
- map.addLayer(gLayer);
- gLayer.on("click",function(feature){
- console.log(feature);
- });
- var wkts = [
- "POINT(107.5758285931443 29.7822116459692)",
- "LINESTRING(120.18304604073 30.3305841465568,108.805692477062 32.0850224203499)",
- "POLYGON((102.797302689433 36.5936423859273,105.519115206186 29.4789248520356,100.346180647351 19.9699202912212))"
- ];
- map.on("load",function(){
- for(var i=0,len = wkts.length;i<len;i++){
- var primitive = Terraformer.WKT.parse(wkts[i]);
- var arcgis = Terraformer.ArcGIS.convert(primitive);
- var geometry = geometryJsonUtils.fromJson(arcgis);
- var symbol = getSymbol(geometry.type);
- var gfx = new Graphic(geometry,symbol);
- gLayer.add(gfx);
- }
- });
- function getSymbol(geotype){
- var symbol = null;
- if(geotype==="point"){
- symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 12,
- new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
- new Color([255,0,0]), 1),
- new Color([0,0,255,255]));
- }
- else if(geotype==="polyline"){
- symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
- new Color([255,0,0]), 2);
- }
- else{
- symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
- new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
- new Color([255,0,0]), 2),new Color([255,255,0,0.25])
- );
- }
- return symbol;
- }
- });
- </script>
- </head>
- <body>
- <div id="map"></div>
- </body>
- </html>
效果:
2、leaflet加载WKT
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
- <title>leaflet</title>
- <link rel="stylesheet" href="../../plugin/leaflet/leaflet.css" type="text/css">
- <style>
- body {
- padding: 0;
- margin: 0;
- }
- html, body, #map {
- height: 100%;
- }
- .leaflet-control-attribution{
- display: none;
- }
- </style>
- <script src="../../plugin/jquery/jquery-1.8.3.js"></script>
- <script src="../../plugin/terraformer/terraformer.js"></script>
- <script src="../../plugin/terraformer/terraformer-wkt-parser.js"></script>
- <script src="../../plugin/leaflet/leaflet.js"></script>
- <script>
- var map;
- $(window).load(function() {
- map = L.map('map').setView([35.851354460363,104.21390114103], 4);//35.851354460363,104.21390114103
- var wms = L.tileLayer.wms("http://localhost:8088/geoserver/lzugis/wms", {
- layers: 'province',
- format: 'image/png',
- transparent: true,
- version:'1.1.1'
- });
- map.addLayer(wms);
- function onEachFeature(feature, layer) {
- var popupContent = "<p>I started out as a WKT " +
- feature.type + ", but now I'm a Leaflet vector!</p>";
- if (feature.properties && feature.properties.popupContent) {
- popupContent += feature.properties.popupContent;
- }
- layer.bindPopup(popupContent);
- }
- var wkts = [
- "POINT(107.5758285931443 29.7822116459692)",
- "LINESTRING(120.18304604073 30.3305841465568,108.805692477062 32.0850224203499)",
- "POLYGON((102.797302689433 36.5936423859273,105.519115206186 29.4789248520356,100.346180647351 19.9699202912212))"
- ];
- var geojsons = [];
- for(var i=0,len = wkts.length;i<len;i++){
- var geojson = Terraformer.WKT.parse(wkts[i]);
- geojsons.push(geojson);
- }
- var layer = L.geoJson(geojsons, {onEachFeature: onEachFeature}).addTo(map);
- });
- </script>
- </head>
- <body>
- <div id="map"></div>
- </body>
- </html>
效果:
--------------------------------------------
(转)WKT转换工具terraformers的更多相关文章
- Unicode编码解码在线转换工具
// Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...
- android px,dp,sp大小转换工具
package com.voole.playerlib.util; import android.content.Context; /** * Android大小单位转换工具类<br/> ...
- Json与javaBean之间的转换工具类
/** * Json与javaBean之间的转换工具类 * * {@code 现使用json-lib组件实现 * 需要 * json-lib-2.4-jdk15.jar * ...
- Rsa加解密Java、C#、php通用代码 密钥转换工具
之前发了一篇"TripleDes的加解密Java.C#.php通用代码",后面又有项目用到了Rsa加解密,还是在不同系统之间进行交互,Rsa在不同语言的密钥格式不一样,所以过程中主 ...
- ubuntu下编码转换工具
ubuntu打开windows下的txt或者代码文件,经常会出现乱码, ubuntu自带一种转换工具,是命令行的,下面提供一种最简单的方法进行转换 比如要转换的文件为1.txt,进入1.txt的目录 ...
- 日期转换工具类 CommUtil.java
package com.util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.ut ...
- 视频转换工具 Transmageddon
点这里 Transmageddon 是一个采用 Python 语言开发的视频转换工具,支持输出几乎所有的视频格式,同时也可以生成指定平台下的视频格式. 软件界面如下图所示
- Base64 图片转换工具
以前在写asp的后台的时候,有一个上传功能是必须的,那时候进行的图片预览(未上传前)其实就是获取本地的图片路径来显示图片,但是随着HTML5的出现,可以把图片通过编码来实现预览. 在雅虎的36条速度优 ...
- web字体格式及几种在线格式转换工具介绍
原文地址:http://blog.csdn.net/xiaolongtotop/article/details/8316554 目前,文字信息仍是网站最主要的内容,随着CSS3技术的不断成熟,Web字 ...
随机推荐
- Cocos2d-x 脚本语言Lua基本数据结构-表(table)
Cocos2d-x 脚本语言Lua基本数据结构-表(table) table是Lua中唯一的数据结构.其它语言所提供的数据结构,如:arrays.records.lists.queues.sets等. ...
- centos内核编译配置
1.下载内核,下面是内核官网地址:https://www.kernel.org/ tar.xz 是完整的内核包(完整的内核包是通过两次压缩得到的.一次是xz,一次是tar) pgp 是 ...
- Python 不同对象比較大小
万恶的源泉: Fireboo的疑问(当然 lambda 本身写的就有问题): >>> filter( lambda x: x > 2, [ 1, [ 1, 2, 3 ], 2, ...
- webpack之傻瓜式教程(转载)
1.安装好nodejs,安装过程网上找. 2.在D盘.E盘或任意一个磁盘中新建文件夹,命名为webpack_demo: 3.在webpack_demo文件下按住Shift键后点击鼠标右键,再左键点击“ ...
- 【bzoj3288】Mato矩阵
题目大意:给定一个n阶行列式,第i行第j列为GCD(i,j),求这个行列式的值 高斯消元之后发现对角线上的东西是phi 于是线性筛出所有的欧拉函数即可 #include<algorithm> ...
- 20170623_oracle_优化与体系结构
一般优化技巧 建议不用"*"代替所有列名 删除所有数据用TRUNCATE代替DELETE 用NOT EXISTS 代替NOT IN 用EXISTS代替IN 用EXISTS代替DIS ...
- ios32---线程的状态
// // ViewController.m // 04-了解-线程的状态 // // 创建线程是处于新建状态,start是就绪状态,会放入到可调度线程池里面(cpu看线程是否可以调用,是看线程是否在 ...
- 在java中除去字符串(String)中的换行字符(\r \n \t)
我们先来看几个例子: 例1: public class Test { public static void main(String[] args) { String s = "'sds gd ...
- C# 函数的传值与传址(转)
http://www.cnblogs.com/mdnx/archive/2012/09/04/2671060.html using System; using System.Collections.G ...
- window环境下在anconda中安装opencv
今日学习CNN神经网络,在用keras框架下搭建一个简单的模型的时候需要import cv2,我尝试了一下几种方法: 1. 在prompt输入 pip intall opencv-python 出现如 ...