flex 中GML转换_iteye_17466的博客-程序员秘密

技术标签: 技术杂绘  

  package org.openscales.core.format
  {
  import flash.utils.getQualifiedClassName;
  import flash.xml.XMLNode;
  import org.openscales.core.Util;
  import org.openscales.core.feature.Feature;
  import org.openscales.core.geometry.Collection;
  import org.openscales.core.geometry.LineString;
  import org.openscales.core.geometry.LinearRing;
  import org.openscales.core.geometry.MultiLineString;
  import org.openscales.core.geometry.MultiPoint;
  import org.openscales.core.geometry.MultiPolygon;
  import org.openscales.core.geometry.Point;
  import org.openscales.core.geometry.Polygon;
  import org.openscales.proj4as.Proj4as;
  import org.openscales.proj4as.ProjPoint;
  import org.openscales.proj4as.ProjProjection;
  import org.openscales.core.feature.Feature;
  import org.openscales.core.feature.PointFeature;
  import org.openscales.core.feature.MultiPointFeature;
  import org.openscales.core.feature.LineStringFeature;
  import org.openscales.core.feature.MultiLineStringFeature ;
  import org.openscales.core.feature.PolygonFeature;
  import org.openscales.core.feature.MultiPolygonFeature;
  import org.openscales.core.Trace;
  /**
  * Read/Write GML. Supports the GML simple features profile.
  */
  public class GMLFormat extends Format
  {
  protected var _featureNS:String = "http://openscales.org/OpenScales";
  protected var _featureName:String = "featureMember";
  protected var _featurePrefix:String = "OpenScales";
  protected var _layerName:String = "features";
  protected var _geometryName:String = "geometry";
  protected var _collectionName:String = "FeatureCollection";
  protected var _gmlns:String = "http://www.opengis.net/gml";
  protected var _gmlprefix:String = "gml";
  protected var _wfsns:String = "http://www.opengis.net/wfs";
  protected var _wfsprefix:String = "wfs";
  private var _extractAttributes:Boolean = true;
  private var _dim:Number;
  /**
  * GMLFormat constructor
  *
  * @param extractAttributes
  *
  */
  public function GMLFormat(extractAttributes:Boolean = true) {
  this.extractAttributes = extractAttributes;
  }
  /**
  * Read data
  *
  * @param data data to read/parse.
  *
  * @return features.
  */
  override public function read(data:Object):Object {
  var dataXML:XML = null;
  if (typeof data == "string") {
  dataXML = new XML(data);
  } else {
  dataXML = XML(data);
  }
  var featureNodes:XMLList = dataXML..*::featureMember;
  if (featureNodes.length() == 0) { return []; }
  var dim:int;
  var coordNodes:XMLList = featureNodes[0].*::posList;
  if (coordNodes.length() == 0) {
  coordNodes = featureNodes[0].*::pos;
  }
  if (coordNodes.length() > 0) {
  dim = coordNodes[0][email protected]*::srsDimension;
  }
  this.dim = (dim == 3) ? 3 : 2;
  var features:Array = [];
  for (var i:int = 0; i Array = new Array();
  var feature:Feature = null;
  if (xmlNode..*::MultiPolygon.length() > 0) {
  var multipolygon:XML = xmlNode..*::MultiPolygon[0];
  geom = new MultiPolygon();
  var polygons:XMLList = multipolygon..*::Polygon;
  for (var i:int = 0; i 0) {
  var multilinestring:XML = xmlNode..*::MultiLineString[0];
  geom = new MultiLineString();
  var lineStrings:XMLList = multilinestring..*::LineString;
  for (i = 0; i 0) {
  var multiPoint:XML = xmlNode..*::MultiPoint[0];
  geom = new MultiPoint();
  var points:XMLList = multiPoint..*::Point;
  for (i = 0; i 0) {
  var polygon2:XML = xmlNode..*::Polygon[0];
  geom = this.parsePolygonNode(polygon2);
  } else if (xmlNode..*::LineString.length() > 0) {
  var lineString2:XML = xmlNode..*::LineString[0];
  p = this.parseCoords(lineString2);
  if (p) {
  geom = new LineString(p);
  }
  } else if (xmlNode..*::Point.length() > 0) {
  var point:XML = xmlNode..*::Point[0];
  geom = new MultiPoint();
  p = this.parseCoords(point);
  if (p) {
  geom.addComponent(p[0]);
  }
  }
  if (geom) {
  // Test more specific geom before because for is operator, a lineString is a multipoint for example (inheritance)
  if (geom is MultiPolygon) {
  feature = new MultiPolygonFeature(geom as MultiPolygon);
  } else if (geom is Polygon) {
  feature = new PolygonFeature(geom as Polygon);
  } else if (geom is MultiLineString) {
  feature = new MultiLineStringFeature(geom as MultiLineString);
  } else if (geom is LineString) {
  feature = new LineStringFeature(geom as LineString);
  } else if (geom is MultiPoint) {
  feature = new MultiPointFeature(geom as MultiPoint);
  } else if (geom is Point) {
  feature = new PointFeature(geom as Point);
  } else {
  Trace.warning("GMLFormat.parseFeature: unrecognized geometry);");
  return null;
  }
  feature.name = [email protected];
  if (this.extractAttributes) {
  feature.attributes = this.parseAttributes(xmlNode);
  }
  return feature;
  } else {
  return null;
  }
  }
  /**
  * Parse attributes
  *
  * @param node A XML feature node.
  *
  * @return An attributes object.
  */
  public function parseAttributes(xmlNode:XML):Object {
  var nodes:XMLList = xmlNode.children();
  var attributes:Object = {};
  for(var i:int = 0; i array size
  var rings:Array = new Array(linearRings.length());
  for (var i:int = 0; i array of coords
  */
  public function parseCoords(xmlNode:XML):Array {
  var x:Number, y:Number, left:Number, bottom:Number, right:Number, top:Number;
  var points:Array = new Array();
  if (xmlNode) {
  var coordNodes:XMLList = xmlNode.*::posList;
  if (coordNodes.length() == 0) {
  coordNodes = xmlNode.*::pos;
  }
  if (coordNodes.length() == 0) {
  coordNodes = xmlNode.*::coordinates;
  }
  var coordString:String = coordNodes[0].text();
  var nums:Array = (coordString) ? coordString.split(/[, \n\t]+/) : [];
  while (nums[0] == "")
  nums.shift();
  while (nums[nums.length-1] == "")
  nums.pop();
  for(var i:int = 0; i ");
  for (var i:int=0; i ");
  geomContainer.appendChild(geometryNode);
  var featureNode:XML = new XML("");
  var featureContainer:XML = new XML("");
  featureContainer.appendChild(geomContainer);
  for(var attr:String in feature.attributes) {
  var attrText:XMLNode = new XMLNode(2, feature.attributes[attr]);
  var nodename:String = attr;
  if (attr.search(":") != -1) {
  nodename = attr.split(":")[1];
  }
  var attrContainer:XML = new XML("");
  attrContainer.appendChild(attrText);
  featureContainer.appendChild(attrContainer);
  }
  featureNode.appendChild(featureContainer);
  return featureNode;
  }
  /**
  * create a GML Object
  *
  * @param geometry
  *
  * @return an XML
  */
  public function buildGeometryNode(geometry:Object):XML {
  var gml:XML;
  if (getQualifiedClassName(geometry) == "org.openscales.core.geometry::MultiPolygon"
  || getQualifiedClassName(geometry) == "org.openscales.core.geometry::Polygon") {
  gml = new XML("");
  var polygonMember:XML = new XML("");
  var polygon:XML = new XML("");
  var outerRing:XML = new XML("");
  var linearRing:XML = new XML("");
  linearRing.appendChild(this.buildCoordinatesNode(g eometry.components[0]));
  outerRing.appendChild(linearRing);
  polygon.appendChild(outerRing);
  polygonMember.appendChild(polygon);
  gml.appendChild(polygonMember);
  }
  else if (getQualifiedClassName(geometry) == "org.openscales.core.geometry::MultiLineString"
  || getQualifiedClassName(geometry) == "org.openscales.core.geometry::LineString") {
  gml = new XML("");
  var lineStringMember:XML = new XML("");
  var lineString:XML = new XML("");
  lineString.appendChild(this.buildCoordinatesNode(g eometry));
  lineStringMember.appendChild(lineString);
  gml.appendChild(lineStringMember);
  }
  else if (getQualifiedClassName(geometry) == "org.openscales.core.geometry::MultiPoint") {
  gml = new XML("");
  var parts:Object = "";
  parts = geometry.components;
  for (var i:int = 0; i ");
  var point:XML = new XML("");
  point.appendChild(this.buildCoordinatesNode(parts[ i]));
  pointMember.appendChild(point);
  gml.appendChild(pointMember);
  }
  } else if (getQualifiedClassName(geometry) == "org.openscales.core.geometry::Point") {
  parts = geometry;
  gml = new XML("");
  gml.appendChild(this.buildCoordinatesNode(parts));
  }
  return gml;
  }
  /**
  * Builds the coordinates XmlNode
  *
  * @param geometry
  *
  * @return created xmlNode
  */
  public function buildCoordinatesNode(geometry:Object):XML {
  var coordinatesNode:XML = new XML("");
  [email protected] = ".";
  [email protected] = ",";
  [email protected] = " ";
  var points:Array = null;
  if (geometry.components) {
  if (geometry.components.length > 0) {
  points = geometry.components;
  }
  }
  var path:String = "";
  if (points) {
  for (var i:int = 0; i < points.length; i++) {
  if (this.internalProj != null && this.externalProj != null)
  (points[i] as Point).transform(this.internalProj, this.externalProj);
  path += points[i].x + "," + points[i].y + " ";
  }
  } else {
  if (this.internalProj != null && this.externalProj != null) {
  var p:ProjPoint = new ProjPoint(geometry.x, geometry.y);
  Proj4as.transform(internalProj, externalProj, p);
  geometry.x = p.x;
  geometry.y = p.y;
  }
  path += geometry.x + "," + geometry.y + " ";
  }
  coordinatesNode.appendChild(path);
  return coordinatesNode;
  }
  //Getters and Setters
  public function get extractAttributes():Boolean {
  return this._extractAttributes;
  }
  public function set extractAttributes(value:Boolean):void {
  this._extractAttributes = value;
  }
  public function get dim():Number {
  return this._dim;
  }
  public function set dim(value:Number):void {
  this._dim = value;
  }
  public function get internalProj():ProjProjection {
  return this._internalProj;
  }
  public function set internalProj(value:ProjProjection):void {
  this._internalProj = value;
  }
  public function get externalProj():ProjProjection {
  return this._externalProj;
  }
  public function set externalProj(value:ProjProjection):void {
  this._externalProj = value;
  }
  }
  }
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/iteye_17466/article/details/82362588

智能推荐

aptitude管理维护工具_choujing8318的博客-程序员秘密

一、安装软件 sudo aptitude installquota #系统会自动安装软件依赖关系的包 二、重新安装一个软件 sudo aptitude reinstallquota 三、查询软件包信息 aptitude show...

mac使用brew安装mysql_brew 安装的mysql配置文件在哪_shibai906的博客-程序员秘密

mac使用brew安装mysql首先使用brew install [email protected]配置环境变量启动mysql设置密码首先使用brew install [email protected]如果想查看版本,直接使用brew search mysql.配置环境变量现在都安装了zsh,在vim ~/.zshrc配置环境变量。一般使用brew安装的文件都在:/usr/local/Cellar/下。我的mysql...

html控件、html服务器控件等的区别详解_weixin_30340745的博客-程序员秘密

asp.net之所以现在开发方便和快捷,关键是它有一组强大的控件库,包括web服务器控件,web用户控件,web自定义控件,html服务器控件和html控件等。这里我主要说说html控件、html服务器控件和web服务器控件的区别。 1、html控件:就是我们通常的说的html语言标记,这些语言标记在已往的静态页面和其他网页里存在,不能在服务器端控制的,只能在客户端通过javascript和...

区块链以太坊学习笔记_chen_hui.778的博客-程序员秘密

以太坊物联网区块链(一)Web3js 与 java 连接区块链可以参考我github上的两个小demoEthereum-javaEthereum-javascript搭建私有链, 利用以太坊平台完成数据上链如何搭建?用Geth搭建一个区块链节点,本地主机就和区块链网络中主机一致了,(可以连接main链,和其它测试链,还有自定义链)。注:可以通过赋予chainid和networkid不同的值让本机成为连接在main链chainid(1),测试链chanid(2-4)或者自定义链chainid(其它

FPGA模拟SENSOR,MIPI CSI-2发送图像到RV1126_sdi转mipi_anhuihbo的博客-程序员秘密

FPGA实现MIPI CSI-2发送,扩展了RV1126的视频输入接口。FPGA可实现LVDS,Cameralink,HDMI,SDI,自定义通信接口等向MIPI CSI的转换

【原】Android - could not read ok from ADB Server * failed to start daemon * error: cannot connect to d_alex_suen的博客-程序员秘密

在使用真机调试Android程序时,出现如标题的失败提示信息。照例搜索stackoverflow.com,找到解决方法。此文以windows环境为例。首先,打开命令行工具,查看失败信息中提示的端口是否被占用(比如我这边提示的是5037) netstat -ano | findstr :5037如果端口被占用,在任务列表中找到占用端口的进程(可在上一步中查看) tasklist | find

随便推点

毕业设计matlab在误差处理中的应用,毕业设计matlab在误差处理中的应用.doc_weixin_39609622的博客-程序员秘密

毕业设计matlab在误差处理中的应用.doc 陕西理工学院毕业设计论文毕业论文任务书院系机械工程学院专业班级测控082级学生姓名马魁一、毕业论文题目MATLAB在误差理论中的应用二、毕业论文工作自_________年_____月_____日起至_________年月_____日止三、毕业论文进行地点陕西理工学院四、毕业论文内容要求传统的数据处理方法基于数理统计的理论,计算量较大,数据繁多。MAT...

Bootstrap的表格渲染_weixin_34032792的博客-程序员秘密

html &lt;div class="bootstrap-table"&gt; &lt;div class="fixed-table-container" style="padding-bottom: 0px;"&gt; &lt;div class="fixed-table-body"&gt; ...

区块链~Merkle Tree(默克尔树)算法解析~转载_瓦哥架构实战的博客-程序员秘密

/*最近在看Ethereum,其中一个重要的概念是Merkle Tree,以前从来没有听说过,所以查了些资料,学习了Merkle Tree的知识,因为接触时间不长,对Merkle Tree的理解也不是很深入,如果有不对的地方,希望各位大神指正*/Merkle Tree概念    Merkle Tree,通常也被称作Hash Tree,顾名思义,就是存储hash值的一棵树。Merkle树...

Android 魅族 线性马达 mEngine 震动适配_android 线性马达震动api_Night999的博客-程序员秘密

在点击事件中加入以下代码即可view.performHapticFeedback(31011);

java网络编程nio视频学习_weixin_32822759的博客-程序员秘密

java网络编程nio视频学习地址:https://www.bilibili.com/video/BV1Z4411C7iW?p=1

linux性能调分析及调优_-无-为-的博客-程序员秘密

linux性能调分析及调优http://blog.csdn.net/hn2002/article/details/7426907Linux 性能分析以及调优介绍    写在前面:计算机要解决的基本问题之一是如何在不增添更多硬件能力的情况下使其能够完成更多工作;而我们应用设计的一项重要伸缩性原则是:随着应用的推广和访问流量的增加,通过相应数量的服务器资源来应对;资源的消耗应该

推荐文章

热门文章

相关标签