[mapguide-users] Thematic Taking so much of time
Kenneth Skovhede, GEOGRAF A/S
ks at geograf.dk
Tue Feb 10 07:03:32 EST 2009
You need to profile your code to pinpoint the problem.
Until you figure out where the actual problem is, you can't expect help
with it.
If you have never profiled code before, try some of these links:
http://www.google.com/search?q=profiling+.net+code
Chances are, that once you find the problem, you can solve it yourself.
Code like this is likely a performance killer:
areaDoc = New XmlDocument()
areaDoc.LoadXml(areaRuleXML)
areaNode = doc.ImportNode(areaDoc.DocumentElement, True)
areaTypeStyle.AppendChild(areaNode)
Regards, Kenneth Skovhede, GEOGRAF A/S
padmini godavarthi skrev:
> 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
>
More information about the mapguide-users
mailing list