[mapguide-users] Thematic Mapping
padmini godavarthi
godavarthi.padmini at gmail.com
Sun Feb 1 23:22:29 EST 2009
Hi z,
Thanku very much for ur suggestions.i will respect it.
but i understood the answer given by Chris.
But i think its not correct solution for my original query.
i want to display different colors to the different polygons.
but while applying 2 colors in the InterpolateColor function it doesn't
change in different colors
while (dataReader.ReadNext())
{
value = GetFeaturePropertyValue(dataReader, "FeatId");
filterText = """ + "FeatId" + "" = ";
filterText = filterText + value;
areaRuleXML = String.Format(areaRuleTemplate,
"FeatId" + ":" + value,
filterText,
InterpolateColor(portion, "C2C3C4", "C2C3C4", 0), InterpolateColor(portion,
"000000", "000000", 0));
areaDoc = new XmlDocument();
areaDoc.LoadXml(areaRuleXML);
areaDoc.Save("C:\\theme.xml");
areaNode = doc.ImportNode(areaDoc.DocumentElement, true);
areaTypeStyle.AppendChild(areaNode);
portion = portion + increment;
}
it displays some yash color to all the polygons,but i want different color
to the different polygons
Can u plz help me
Thanks and Regards,
Padmini G.
zspitzer wrote:
>
> when someone takes times to provide a response, it's respectful to taking
> a bit more time to read your original email AGAIN !
>
> your calling
>
> InterpolateColor(portion, "C2C3C4", "C2C3C4", 0),
> InterpolateColor(portion,"C2C3C4", "C2C3C4", 0));
>
> which takes two colors to create a range, yet you pass in the same
> color twice....
>
> sorry if I sound a bit grumpy, but it appears that Chris spent more
> time reading
> your email that you did after his reply....
>
> z
>
>
>
> On Sat, Jan 31, 2009 at 7:57 PM, padmini godavarthi
> <godavarthi.padmini at gmail.com> wrote:
>>
>> Hi,
>> Thanks for ur reply.but i didn't get u
>> can u plz tell me briefly so that it will be helpful to me.
>>
>>
>> Thanks and Regards,
>> Padmini.
>>
>>
>> Chris Claydon wrote:
>>>
>>> I would recommend modifying your call to InterpolateColor() so that the
>>> start color and end color correspond to the colors you want. They are
>>> currently both set to the same string.
>>>
>>> -----Original Message-----
>>> From: mapguide-users-bounces at lists.osgeo.org
>>> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of padmini
>>> godavarthi
>>> Sent: Friday, January 30, 2009 3:59 AM
>>> To: mapguide-users at lists.osgeo.org
>>> Subject: [mapguide-users] Thematic Mapping
>>>
>>>
>>>
>>>
>>> Hi,
>>> iam using mpguide opensource 2.0 (.net 2.0 +IIS 5.1).
>>> I want to do thematic mapping for polygon layer(for example parcel
>>> layer)
>>> i tried to use the code in dotnetviewer sample.its working fine
>>>
>>> iam able to create a thematic layer with same color to the all polygons.
>>> Now my problem is that i want to apply different colours to the
>>> different
>>> polygons
>>>
>>> for example for parcel_id =1 ------------ green colour
>>> for example for parcel_id =2 ------------ Red colour and
>>> soon.........................
>>>
>>> for this can u plz tell me the code for how to do it?
>>>
>>>
>>> my code was as follows
>>> ------------------------------------------------------------------------------------------------------
>>>
>>>
>>> NameValueCollection serverVars = Request.ServerVariables;
>>> String strServerVars = "";
>>> foreach (String str in serverVars.AllKeys)
>>> {
>>>
>>> strServerVars += "<br>" + str;
>>>
>>> }
>>> String platform = serverVars["SERVER_SOFTWARE"];
>>> String queryStr = serverVars["QUERY_STRING"];
>>> string queryStr1 = serverVars["Form"];
>>> NameValueCollection requestParams = Request.HttpMethod == "POST"
>>> ?
>>> Request.Form : Request.QueryString;
>>> String sessionId = Request.QueryString["SESSION"];
>>> string realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
>>> String configPath = realPath + "webconfig.ini";
>>> MapGuideApi.MgInitializeWebTier(configPath);
>>> MgUserInformation userInfo = new MgUserInformation(sessionId);
>>> MgSiteConnection siteConnection = new MgSiteConnection();
>>> siteConnection.Open(userInfo);
>>> MgResourceService resourceService =
>>> (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
>>> MgFeatureService featureService =
>>> (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
>>>
>>> MgMap map = new MgMap();
>>> map.Open(resourceService, "mapdata");
>>> MgLayerCollection layers = map.GetLayers();
>>> MgLayer layer = (MgLayer)layers.GetItem("property layer");
>>>
>>> MgResourceIdentifier resId = new
>>> MgResourceIdentifier(layer.GetFeatureSourceId());
>>> MgResourceIdentifier layerDefResId = layer.GetLayerDefinition();
>>> MgByteReader byteReader =
>>> resourceService.GetResourceContent(layerDefResId);
>>>
>>> // Load the Layer Definition and Navigate to the specified
>>> <VectorScaleRange>
>>>
>>> XmlDocument doc = new XmlDocument();
>>> String xmlLayerDef = byteReader.ToString();
>>> doc.LoadXml(xmlLayerDef);
>>> XmlNodeList nodeList =
>>> doc.GetElementsByTagName("VectorScaleRange");
>>>
>>> XmlElement vectorScaleRangecElement = (XmlElement)nodeList.Item(0);
>>> XmlElement areaTypeStyle =
>>> (XmlElement)vectorScaleRangecElement.GetElementsByTagName("AreaTypeStyle").Item(0);
>>>
>>> // Remove any existing <AreaRule> elements.
>>>
>>> XmlNodeList areaRuleList =
>>> areaTypeStyle.GetElementsByTagName("AreaRule");
>>> int count = areaRuleList.Count;
>>> for (int i = 0; i < count; i++)
>>> {
>>> //The areaRuleList shrinks as we remove items, so always
>>> //remove the first item (don't use the index i)
>>> areaTypeStyle.RemoveChild(areaRuleList.Item(0));
>>> }
>>>
>>> // Now create the new <AreaRule> elements.
>>>
>>> String areaRuleTemplate =
>>> File.ReadAllText(GetThemeXmlTemplatePath());
>>> MgFeatureAggregateOptions aggregateOptions = new
>>> MgFeatureAggregateOptions();
>>>
>>> String value = null;
>>> String filterText = null;
>>> String areaRuleXML = null;
>>> XmlDocument areaDoc = null;
>>> XmlNode areaNode = null;
>>> double portion = 0.0;
>>>
>>> aggregateOptions.AddFeatureProperty("FeatId");
>>> aggregateOptions.SelectDistinct(true);
>>> aggregateOptions.SetFilter(totquery);
>>> double increment = (5 > 1) ? 1.0 / (5 - 1) : 1.0;
>>> MgDataReader dataReader =
>>> featureService.SelectAggregate(resId,
>>> layer.GetFeatureClassName(), aggregateOptions);
>>> while (dataReader.ReadNext())
>>> {
>>> value = GetFeaturePropertyValue(dataReader, "FeatId");
>>>
>>> filterText = """ + "FeatId" + "" = ";
>>>
>>> filterText = filterText + value;
>>>
>>> areaRuleXML = String.Format(areaRuleTemplate,
>>> "FeatId" + ":" + value,
>>> filterText,
>>> InterpolateColor(portion, "C2C3C4", "C2C3C4", 0),
>>> InterpolateColor(portion,
>>> "C2C3C4", "C2C3C4", 0));
>>> areaDoc = new XmlDocument();
>>> areaDoc.LoadXml(areaRuleXML);
>>> areaDoc.Save("C:\\theme.xml");
>>> areaNode = doc.ImportNode(areaDoc.DocumentElement,
>>> true);
>>> areaTypeStyle.AppendChild(areaNode);
>>>
>>>
>>> portion = portion + increment;
>>> }
>>> dataReader.Close();
>>>
>>>
>>> // Now save our new layer definition to the session and add it
>>> to
>>> the map.
>>>
>>> String xmlString = doc.DocumentElement.OuterXml;
>>> String uniqueName = this.MakeUniqueLayerName(map, "property
>>> layer",
>>> "sample");
>>> String legendLabel = layer.GetLegendLabel();
>>> if ("sample".Length > 0)
>>> legendLabel = legendLabel + " (" + "sample" + ")";
>>>
>>> MgResourceIdentifier layerResId = new
>>> MgResourceIdentifier("Session:" + sessionId + "//" + uniqueName +
>>> ".LayerDefinition");
>>> resourceService.SetResource(layerResId, new
>>> MgByteReader(xmlString,
>>> "text/xml") , null);
>>>
>>> MgLayer newLayer = new MgLayer(layerResId, resourceService);
>>> newLayer.SetName(uniqueName);
>>> newLayer.SetLegendLabel(legendLabel);
>>> newLayer.SetDisplayInLegend(layer.GetDisplayInLegend());
>>> newLayer.SetVisible(true);
>>> newLayer.SetSelectable(layer.GetSelectable());
>>> layers.Insert(layers.IndexOf(layer), newLayer);
>>>
>>> map.Save(resourceService);
>>>
>>> return uniqueName;
>>> }
>>> ---------------------------------------------
>>> private String InterpolateColor(double portion, String startColor,
>>> String
>>> endColor, int percentTransparent)
>>> {
>>> int alpha = (int)(255 * (100.0 - percentTransparent) / 100.0);
>>> String result = "";
>>> if (startColor.Equals(endColor))
>>> {
>>> result = String.Format("{0:X2}{1}", alpha, startColor);
>>> }
>>> else
>>> {
>>> int red = CalculateRGB(portion, startColor.Substring(0, 2),
>>> endColor.Substring(0, 2));
>>> int green = CalculateRGB(portion, startColor.Substring(2,
>>> 2),
>>> endColor.Substring(2, 2));
>>> int blue = CalculateRGB(portion, startColor.Substring(4, 2),
>>> endColor.Substring(4, 2));
>>> result = String.Format("{0:X2}{1:X2}{2:X2}{3:X2}", alpha,
>>> red,
>>> green, blue);
>>> }
>>> return result;
>>> }
>>>
>>> private String MakeUniqueLayerName(MgMap map, String layerName,
>>> String
>>> themeName)
>>> {
>>> String desiredName = "_" + layerName + themeName;
>>> String uniqueName = desiredName;
>>> int index = 1;
>>>
>>> while (map.GetLayers().Contains(uniqueName))
>>> {
>>> uniqueName = desiredName + index.ToString();
>>> index++;
>>> }
>>> return uniqueName;
>>> }
>>> private int CalculateRGB(double portion, String startRGB, String
>>> endRGB)
>>> {
>>> double result = Int32.Parse(startRGB, NumberStyles.HexNumber) +
>>> portion * (Int32.Parse(endRGB, NumberStyles.HexNumber) -
>>> Int32.Parse(startRGB, NumberStyles.HexNumber));
>>> return (int)result;
>>> }
>>> String GetThemeXmlTemplatePath()
>>> {
>>> String xmlTemplatePath ="D:\\arearuletemplate.xml";
>>> return xmlTemplatePath;
>>> }
>>> ---------------------------------------
>>> can u plz tell me the solution?
>>>
>>> Regards,
>>> Padmini.
>>>
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/Thematic-Mapping-tp2244230p2244230.html
>>> Sent from the MapGuide Users mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> mapguide-users mailing list
>>> mapguide-users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>> _______________________________________________
>>> mapguide-users mailing list
>>> mapguide-users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>
>>>
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/Thematic-Mapping-tp2244230p2249312.html
>> Sent from the MapGuide Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>
>
>
>
> --
> Zac Spitzer -
> http://zacster.blogspot.com
> +61 405 847 168
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>
--
View this message in context: http://n2.nabble.com/Thematic-Mapping-tp2244230p2256479.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list