当我们要把一个地块导出为txt的时候,应该怎么写,这是比较有用的这样可以帮助我们存档之类的,这里是基于某个地方的独立坐标系,是基于自己发布地图,如果是用百度地图或者其他网上的地图可能不适用。
package com.szpl.extension.util
{
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Polygon;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.symbols.SimpleFillSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
import com.szpl.extension.util.shp.shp.ShpPolygon; import flash.geom.Point; public class PointPolygonExchange
{
public function PointPolygonExchange()
{
} private var _pointstr:String=""; public function get pointstr():String
{
return _pointstr;
} public function set pointstr(value:String):void
{
_pointstr = value;
} // "x,y x,y x,y*x,y x,y..."
public function coordText_to_polygon(coordText:String):Polygon
{
var ringsText:Array = coordText.split("*"); var polygon:Polygon = new Polygon();
for each(var ringText:String in ringsText)
{
var ring:Array = coordText_to_Ring(ringText);
if(ring==null)
continue;
polygon.addRing(ring);
}
return polygon;
} public var xyChange:String = "x"; public function polygon_to_CoordText(polygon:*):String
{
var _polygon:Polygon = new Polygon();
if (polygon is ShpPolygon)
{
_polygon = (polygon as ShpPolygon).toPolygon();
}
else
{
_polygon = polygon as Polygon
}
xyChange = "x";
var polygonText:String="";
for each(var ring:Array in _polygon.rings)
{
var ringText:String = ring_to_CoordText(ring);
polygonText += ringText;
polygonText += "*";
} return polygonText.substr(0,polygonText.length -1);
} public function polygon_to_CoordTextXY(polygon:*):String
{
xyChange = "y";
var polygonText:String="";
for each(var ring:Array in polygon.rings)
{
var ringText:String = ring_to_CoordText(ring);
polygonText += ringText;
polygonText += "*";
} return polygonText.substr(0,polygonText.length -1);
} private function ring_to_CoordText(points:Array):String
{
var ringText:String="";
for each(var point:MapPoint in points)
{
var pointText:String = point_to_CoordText(point);
ringText += pointText;
ringText += " ";
}
return ringText.substr(0,ringText.length-1);
} private function coordText_to_Ring(coordText:String):Array
{
if(coordText=="")
return null;
var pointsText:Array = coordText.split(" ");
var ring:Array = new Array();
for each(var pointText:String in pointsText)
{
if(pointText!="")
{
var point:MapPoint = coordText_to_Point(pointText);
if (point != null)
ring.push(point);
} }
if (ring.length < 3)
return null;
ring.push(new MapPoint((ring[0] as MapPoint).x,(ring[0] as MapPoint).y));
return ring;
} private function point_to_CoordText(point:MapPoint):String
{
var x:String = point.x.toString();
var y:String = point.y.toString();
if(xyChange == "x")
return x + "," + y;
else
return y + "," + x;
} /// "343.234,23423.534"
private function coordText_to_Point(coordText:String):MapPoint{ var coord:Array = coordText.split(",");
if (coord.length != 2)
return null;
var x:Number = coord[1];
var y:Number = coord[0];
var point:MapPoint;
if (x > y)
point = new MapPoint(x, y, null);
else
point = new MapPoint(y, x, null);
return point;
} // "\r\n" ====> " "
public function txtFile_to_CoordText(txtFile:String):String
{
var regE:RegExp = new RegExp("\r\n", "g");
var str:String = txtFile.replace(regE," ");
return str;
} }
}