elven_cris
2008-05-08 17:54:08 UTC
We are searching a map solution which allows to draw the US map whith the 5
digit zip code border (to create a custom application for a US financial
company). The problem is I cannot find a way to do it in MapPoint.
I tried to get the PostCode1 entities from MapPoint.NA and to draw them as
Polygons, but it gives me the Exception "The specified DataSource object
either does not exist, is not a Polygon datasource, or you are not authorized
to use it. Argument: specification.Polygon[0].DataSourceName".
Do you know a way to draw the zip codes border, or why is this not working?
Here is the code:
FindSpecification findZipCodes = new FindSpecification();
findZipCodes.DataSourceName = "MapPoint.NA";
findZipCodes.InputPlace = "1";
findZipCodes.Options = new FindOptions();
findZipCodes.Options.ThresholdScore = 0;
findZipCodes.EntityTypeNames = new string[] { "Postcode1" };
findZipCodes.Options.Range = new FindRange();
findZipCodes.Options.Range.StartIndex = 0;
findZipCodes.Options.Range.Count = 50;
FindResults foundZips;
foundZips = _mapPointServices.Finder.Find(findZipCodes);
Polygon[] zipPoly = new Polygon[foundZips.Results.Length];
ElementColor color = new ElementColor();
for (int i = 0; i < foundZips.Results.Length; i++)
{
Polygon poly = new Polygon();
poly.DataSourceName =
foundZips.Results[i].FoundLocation.DataSourceName;
poly.EntityID = foundZips.Results[i].FoundLocation.Entity.ID;
poly.BorderColor = color;
poly.FillColor = color;
zipPoly[i] = poly;
}
FindSpecification findSpec = new FindSpecification();
findSpec.DataSourceName = "MapPoint.NA";
findSpec.InputPlace = "1, CA";
FindResults foundResults =
_mapPointServices.Finder.Find(findSpec);
// Set up a MapOptions object.
MapOptions mo = new MapOptions();
mo.Format = new ImageFormat();
mo.Format.MimeType = "image/jpeg";
mo.Format.Height = height;
mo.Format.Width = width;
mo.ReturnType = MapReturnType.ReturnImage;
mo.Style = MapStyle.Political;
ViewByScale[] viewByScale = new ViewByScale[1];
viewByScale[0] = new ViewByScale();
viewByScale[0].CenterPoint =
foundResults.Results[0].FoundLocation.LatLong;
viewByScale[0].MapScale = scale;
// Set up a MapSpecification object.
MapSpecification spec = new MapSpecification();
spec.DataSourceName = "MapPoint.NA";
spec.Views = viewByScale;
spec.Options = mo;
spec.Polygons = zipPoly;
MapImage[] mi = _mapPointServices.Render.GetMap(spec);
return new Bitmap(new
System.IO.MemoryStream(mi[0].MimeData.Bits));
digit zip code border (to create a custom application for a US financial
company). The problem is I cannot find a way to do it in MapPoint.
I tried to get the PostCode1 entities from MapPoint.NA and to draw them as
Polygons, but it gives me the Exception "The specified DataSource object
either does not exist, is not a Polygon datasource, or you are not authorized
to use it. Argument: specification.Polygon[0].DataSourceName".
Do you know a way to draw the zip codes border, or why is this not working?
Here is the code:
FindSpecification findZipCodes = new FindSpecification();
findZipCodes.DataSourceName = "MapPoint.NA";
findZipCodes.InputPlace = "1";
findZipCodes.Options = new FindOptions();
findZipCodes.Options.ThresholdScore = 0;
findZipCodes.EntityTypeNames = new string[] { "Postcode1" };
findZipCodes.Options.Range = new FindRange();
findZipCodes.Options.Range.StartIndex = 0;
findZipCodes.Options.Range.Count = 50;
FindResults foundZips;
foundZips = _mapPointServices.Finder.Find(findZipCodes);
Polygon[] zipPoly = new Polygon[foundZips.Results.Length];
ElementColor color = new ElementColor();
for (int i = 0; i < foundZips.Results.Length; i++)
{
Polygon poly = new Polygon();
poly.DataSourceName =
foundZips.Results[i].FoundLocation.DataSourceName;
poly.EntityID = foundZips.Results[i].FoundLocation.Entity.ID;
poly.BorderColor = color;
poly.FillColor = color;
zipPoly[i] = poly;
}
FindSpecification findSpec = new FindSpecification();
findSpec.DataSourceName = "MapPoint.NA";
findSpec.InputPlace = "1, CA";
FindResults foundResults =
_mapPointServices.Finder.Find(findSpec);
// Set up a MapOptions object.
MapOptions mo = new MapOptions();
mo.Format = new ImageFormat();
mo.Format.MimeType = "image/jpeg";
mo.Format.Height = height;
mo.Format.Width = width;
mo.ReturnType = MapReturnType.ReturnImage;
mo.Style = MapStyle.Political;
ViewByScale[] viewByScale = new ViewByScale[1];
viewByScale[0] = new ViewByScale();
viewByScale[0].CenterPoint =
foundResults.Results[0].FoundLocation.LatLong;
viewByScale[0].MapScale = scale;
// Set up a MapSpecification object.
MapSpecification spec = new MapSpecification();
spec.DataSourceName = "MapPoint.NA";
spec.Views = viewByScale;
spec.Options = mo;
spec.Polygons = zipPoly;
MapImage[] mi = _mapPointServices.Render.GetMap(spec);
return new Bitmap(new
System.IO.MemoryStream(mi[0].MimeData.Bits));