Select to view content in your preferred language

Load WGS84 Local Shapefile and Display in Web Mercator Application

2233
6
11-16-2010 08:57 AM
by Anonymous User
Not applicable
Original User: tbrophy

All,

I downloaded and am using �??Shape File Overlay for Sample Viewer�?� from the ArcGIS resource Center, submitted 3-4-2010 by �??HardWork�?�. It works great, but I need it go a step further.
�??�?�Shape File Overlay for Sample Viewer�?��?�
http://resources.esri.com/arcgisserver/apis/flex/index.cfm?fa=codeGalleryDetails&scriptID=16846

I asked this in a previous forum but thought I would start a new thread. . .
(http://forums.arcgis.com/threads/8268-Load-Local-Shapefile-with-Symbology-and-Attributes)
------------------------------------------------------------------------------------------------------------------------------------

My application is in Web Mercator (102100). So every time my users want to use this tool, they need to convert their shapefile from WGS 1984 Geographic (4326) into Web Mercator (102100) in ArcMap first. Then, and only then, can the shapefile be converted into a graphic and shown in the WM application.

Can anyone show me a way to convert this programmatically?

The conversion would always be the same (4326) -- (102100).

********* My environment *********
Adapted Sample Flex Viewer: flexviewer-src-1.0.zip (Build 06.12.09)
agslib-1.2.swc
flex_sdk_3.2
Required Adobe Flash Player version 10
********* My environment *********

Any help would be greatly appreciated. Attached are my adjust files and one of my sample shapefiles in WGS 1984 Geographic (4326).
0 Kudos
6 Replies
DasaPaddock
Esri Regular Contributor
0 Kudos
by Anonymous User
Not applicable
Original User: tbrophy

You can use this to do the conversion:
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/apiref/com/esri/ags/utils/WebMercatorUtil....


Dasa (or anyone),

I tried the conversion and got it to work half way using the attached wgs84 zipped shapefile, "CHLORINE_Release_Model102100.zip". It zooms the right location (Dallas, TX) but the graphic does not show up. I think the problem is in the "loadShapefile" function, at line:138.

//
private function loadShapefile(shpByteArray:ByteArray, dbfByteArray:ByteArray):void
{
var index:int = 0;
const array:Array = [];
const shpReader:ShpReader = new ShpReader(shpByteArray);
const dbfHeader:DbfHeader = new DbfHeader(dbfByteArray);
while (shpReader.hasMore())
{
var shpPolygon:ShpPolygon = shpReader.readShpPolygon();
var dbfRecord:DbfRecord = DbfTools.getRecord(dbfByteArray, dbfHeader, index++);
var myGraphic:Graphic = new Graphic(shpPolygon, shpSymbol, dbfRecord.values);
array.push(myGraphic);
//array.push(new Graphic(shpPolygon, shpSymbol, dbfRecord.values));
}
/*Code from "Live sample - Bing Maps geocoder"
var veResult:VEGeocodeResult = results[0];
var myGraphic:Graphic = new Graphic();
myGraphic.geometry = WebMercatorUtil.geographicToWebMercator(veResult.location);
myGraphic.symbol = mySymbol;
myGraphic.toolTip = veResult.displayName;
myGraphic.id = "graphic";
myGraphicsLayer.add(myGraphic);
myMap.extent = WebMercatorUtil.geographicToWebMercator(veResult.bestView) as Extent;
*/

//var arrayGraphic:Graphic = new Graphic();
//arrayGraphic.geometry = WebMercatorUtil.geographicToWebMercator(array.location);
//graphicsLayer.add(arrayGraphic);

graphicsLayer.graphicProvider = new ArrayCollection(array);
map.addLayer(graphicsLayer);
//map.extent = shpReader.extent.expand(1.5);
map.extent = WebMercatorUtil.geographicToWebMercator(shpReader.extent.expand(1.5)) as Extent;
msgBox.text = "Polygon footprint has been successfully loaded.";
}
//

CAN ANYONE HELP ME? PLEASE?

The mxml is attached, "ShpOverlay_wgs84.zip".

//My environment is still:
flexviewer-src-1.0.zip (Build 06.12.09)
agslib-1.2.swc
flex_sdk_3.2
//

Sinceraly,
Thomas
0 Kudos
by Anonymous User
Not applicable
Original User: tbrophy

I attached the wrong shapefile.  This is the right test shapefile:

CHLORINE_Release_Model4326.zip

It is in wgs 1984 geographic.

Thomas.
0 Kudos
MelindaFrost
Frequent Contributor
I was implementing this also and was running into the same problem as you. What is missing is converting the graphic to WebMercator too. I am just working with points so this is what I did to get them show up on map

array.push(new Graphic(WebMercatorUtil.geographicToWebMercator(shpPoint.toPoint()), new SimpleMarkerSymbol(styleMark.text.replace(repPattern,"").toLowerCase(),sizeMark.value,cpMark.selectedColor,alphaMark.value/100), dbfRecord.values));
array.push(new Graphic(WebMercatorUtil.geographicToWebMercator(shpPoint.toPoint()), txtSym, dbfRecord.values));
0 Kudos
by Anonymous User
Not applicable
Original User: tbrophy

Melinda,

Thank you for your response. It got me on the right track and figured it out. Here's the final code for "loadShapefile":

private function loadShapefile(shpByteArray:ByteArray, dbfByteArray:ByteArray):void
{
var index:int = 0;
const array:Array = [];
const shpReader:ShpReader = new ShpReader(shpByteArray);
const dbfHeader:DbfHeader = new DbfHeader(dbfByteArray);
graphicsLayer.graphicProvider = new ArrayCollection(array);
while (shpReader.hasMore())
{
var shpPolygon:ShpPolygon = shpReader.readShpPolygon();
var dbfRecord:DbfRecord = DbfTools.getRecord(dbfByteArray, dbfHeader, index++);
//geoToWebM Start
var myGraphic:Graphic = new Graphic();
myGraphic.geometry = WebMercatorUtil.geographicToWebMercator(shpPolygon.toPolygon());
myGraphic.symbol = myPoly;
graphicsLayer.add(myGraphic);
//geoToWebM End
//array.push(new Graphic(shpPolygon, shpSymbol, dbfRecord.values));
}
//graphicsLayer.graphicProvider = new ArrayCollection(array);
map.addLayer(graphicsLayer);
//map.extent = shpReader.extent.expand(1.5);
//geoToWebM Start
map.extent = WebMercatorUtil.geographicToWebMercator(shpReader.extent.expand(2.0)) as Extent;
//geoToWebM End
msgBox.htmlText = "Polygon footprint has been successfully loaded.";
}

I also attached the mxml.

Thanks again!
0 Kudos
LilyChen
Emerging Contributor
Hello, your posts here have been very helpful for me.  I'm also trying to load shapfiles into a map with a spatial reference of 102100.  However, after my shapefile loads, I noticed that it only shows up (at the correct location) if I'm zoomed out all the way, and if I try to zoom in (beyond the 3rd ticker on the zoom bar), the shapefile just disappear. Was wondering if anyone has a clue to why this is happening.

Thanks in advance!
0 Kudos