[mapguide-users] Thematic Taking so much of time
padmini godavarthi
godavarthi.padmini at gmail.com
Fri Feb 6 08:57:15 EST 2009
Hi,
Iam using mapguide opensource 2.0(with .net 2.0 +iiS 5.1)
Now i want to create a thematic layer based on some condition (for suppose
2200 parcels).
Its take so much of time for creating this thematic layer.
My code is as follows
In task pane page (thematic.aspx)button click
Dim value As String = ""
Dim filterText As String = ""
Dim areaRuleXML As String = ""
Dim areaDoc As XmlDocument = Nothing
Dim areaNode As XmlNode = Nothing
Dim portion As Double = 0.0
Dim aggregateOptions1 As MgFeatureAggregateOptions = New
MgFeatureAggregateOptions()
Dim areaRuleTemplate As String =
File.ReadAllText(GetThemeXmlTemplatePath())
aggregateOptions1.AddFeatureProperty("PARCEL_ID")
aggregateOptions1.SelectDistinct(True)
Dim parcelstring As String
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
If parcelstring = "" Then
parcelstring = "'" & ds.Tables(0).Rows(i).Item(0).ToString &
"'"
Else
parcelstring = parcelstring & "," & "'" &
ds.Tables(0).Rows(i).Item(0).ToString & "'"
End If
Next
aggregateOptions1.SetFilter("PARCEL_ID IN(" & parcelstring & ")")
' aggregateOptions1.SetFilter("PARCEL_ID IN('785_1000','670_286')")
Dim increment1 As Double = IIf((5 > 1), 1.0 / (5 - 1), 1.0)
Dim dataReader1 As MgDataReader =
featureService.SelectAggregate(resId, layer.GetFeatureClassName(),
aggregateOptions1)
While dataReader1.ReadNext()
value = GetFeaturePropertyValue(dataReader1, "PARCEL_ID")
' value = "'785_1000'"
filterText = """ + "PARCEL_ID" + "" = "
filterText = filterText + value
areaRuleXML = String.Format(areaRuleTemplate, "PARCEL_ID" + ":"
+ value, filterText, InterpolateColor(portion, "00C000", "00C000", 0),
InterpolateColor(portion, "00C000", "00C000", 0))
areaDoc = New XmlDocument()
areaDoc.LoadXml(areaRuleXML)
' areaDoc.Save("C:\\theme.xml")
areaNode = doc.ImportNode(areaDoc.DocumentElement, True)
areaTypeStyle.AppendChild(areaNode)
portion = portion + increment1
End While
dataReader1.Close()
End Function
Public Function ApplyThematicColor1(ByVal areaTypeStyle As XmlElement,
ByVal doc As XmlDocument, ByVal featureService As MgFeatureService, ByVal ds
As DataSet, ByVal resId As MgResourceIdentifier, ByVal layer As MgLayer)
Dim value As String = ""
Dim filterText As String = ""
Dim areaRuleXML As String = ""
Dim areaDoc As XmlDocument = Nothing
Dim areaNode As XmlNode = Nothing
Dim portion As Double = 0.0
Dim aggregateOptions1 As MgFeatureAggregateOptions = New
MgFeatureAggregateOptions()
Dim areaRuleTemplate As String =
File.ReadAllText(GetThemeXmlTemplatePath())
aggregateOptions1.AddFeatureProperty("PARCEL_ID")
aggregateOptions1.SelectDistinct(True)
Dim parcelstring As String
'For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
' If parcelstring = "" Then
' parcelstring = "'" & ds.Tables(0).Rows(i).Item(0).ToString
& "'"
' Else
' parcelstring = parcelstring & "," & "'" &
ds.Tables(0).Rows(i).Item(0).ToString & "'"
' End If
'Next
'aggregateOptions1.SetFilter("PARCEL_ID IN(" & parcelstring & ")")
aggregateOptions1.SetFilter("PARCEL_ID
IN('709_252','709_407','709_408','708_481')")
Dim increment1 As Double = IIf((5 > 1), 1.0 / (5 - 1), 1.0)
Dim dataReader1 As MgDataReader =
featureService.SelectAggregate(resId, layer.GetFeatureClassName(),
aggregateOptions1)
While dataReader1.ReadNext()
value = GetFeaturePropertyValue(dataReader1, "PARCEL_ID")
' value = "'785_1000'"
filterText = """ + "PARCEL_ID" + "" = "
filterText = filterText + value
areaRuleXML = String.Format(areaRuleTemplate, "PARCEL_ID" + ":"
+ value, filterText, InterpolateColor(portion, "FF0000", "FF0000", 0),
InterpolateColor(portion, "FF0000", "FF0000", 0))
areaDoc = New XmlDocument()
areaDoc.LoadXml(areaRuleXML)
' areaDoc.Save("C:\\theme.xml")
areaNode = doc.ImportNode(areaDoc.DocumentElement, True)
areaTypeStyle.AppendChild(areaNode)
portion = portion + increment1
End While
dataReader1.Close()
End Function
Public Function GetThemeXmlTemplatePath() As String
Dim xmlTemplatePath As String = "D:\\arearuletemplate.xml"
Return xmlTemplatePath
End Function
Private Function CalculateRGB(ByVal portion As Double, ByVal startRGB As
String, ByVal endRGB As String) As Integer
Dim result As Double = Int32.Parse(startRGB, NumberStyles.HexNumber)
+ portion * (Int32.Parse(endRGB, NumberStyles.HexNumber) -
Int32.Parse(startRGB, NumberStyles.HexNumber))
Return result
End Function
Private Function InterpolateColor(ByVal portion As Double, ByVal
startColor As String, ByVal endColor As String, ByVal percentTransparent As
Integer) As String
Dim alpha As Integer = CType((255 * (100.0 - percentTransparent) /
100.0), Integer)
Dim result As String = ""
If (startColor.Equals(endColor)) Then
result = String.Format("{0:X2}{1}", alpha, startColor)
Else
Dim red As Integer = CalculateRGB(portion,
startColor.Substring(0, 2), endColor.Substring(0, 2))
Dim green As Integer = CalculateRGB(portion,
startColor.Substring(2, 2), endColor.Substring(2, 2))
Dim blue As Integer = 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)
End If
Return result
End Function
Public Function GetFeaturePropertyValue(ByVal featureReader As MgReader,
ByVal propName As String) As String
Dim value As String = ""
Dim propertyType As Integer =
featureReader.GetPropertyType(propName)
Select Case propertyType
Case MgPropertyType.Boolean
value = featureReader.GetBoolean(propName).ToString()
Case MgPropertyType.Byte
value = featureReader.GetByte(propName).ToString()
Case MgPropertyType.Single
value = featureReader.GetSingle(propName).ToString()
Case MgPropertyType.Double
value = featureReader.GetDouble(propName).ToString()
Case MgPropertyType.Int16
value = featureReader.GetInt16(propName).ToString()
Case MgPropertyType.Int32
value = featureReader.GetInt32(propName).ToString()
Case MgPropertyType.Int64
value = featureReader.GetInt64(propName).ToString()
Case MgPropertyType.String
value = featureReader.GetString(propName)
value = "'" & value & "'"
Case MgPropertyType.DateTime
Case MgPropertyType.Null
Case MgPropertyType.Blob
Case MgPropertyType.Clob
Case MgPropertyType.Feature
Case MgPropertyType.Geometry
Case MgPropertyType.Raster
value = "[unsupported data type]"
End Select
Return value
End Function
cis there any facility to reduce my time.
Hardly it takes 7 minutes to create layer with 2200 polygons
Can u plz tell me the solution
Thanks and Reegards,
Padmini
--
View this message in context: http://n2.nabble.com/Thematic-Taking-so-much-of-time-tp2284225p2284225.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list