[mapguide-users] select features problem

padmini godavarthi godavarthi.padmini at gmail.com
Wed Apr 29 23:43:55 EDT 2009


Hi,
iam using mapguide opensource 2.0 (with .net 2.0 +IIS 5.1)
i want to slect the features from one layer and create a new layer with that
selected features(link_id =170)

i wrote a code but it comes as a entire layer .
 i want a feature with the link_id 170.



  Dim serverVars As NameValueCollection = Request.ServerVariables
        Dim strServerVars As String = ""

        Dim str1 As String
        For Each str1 In serverVars.AllKeys
            strServerVars += "<br>" & str1
        Next
        Dim platform As String = serverVars("SERVER_SOFTWARE")
        Dim queryStr As String = serverVars("QUERY_STRING")
        Dim queryStr1 As String = serverVars("Form")
        Dim requestParams As NameValueCollection = IIf(Request.HttpMethod =
"POST", Request.Form, Request.QueryString)

        Dim sessionId As String = Request.QueryString("SESSION")
        Dim realPath As String =
Request.ServerVariables("APPL_PHYSICAL_PATH")
        Dim configPath As String = realPath + "webconfig.ini"
        MapGuideApi.MgInitializeWebTier(configPath)
        Dim userInfo As MgUserInformation = New MgUserInformation(sessionId)
        Dim siteConnection As MgSiteConnection = New MgSiteConnection
        siteConnection.Open(userInfo)
        Dim resService As MgResourceService =
siteConnection.CreateService(MgServiceType.ResourceService)
        Dim featureService As MgFeatureService =
siteConnection.CreateService(MgServiceType.FeatureService)
        Dim shortclass As New MgClassDefinition()

        Dim map As MgMap = New MgMap()
        map.Open(resService, "mapdata")
        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 layers As MgLayerCollection = map.GetLayers()
        Dim layer As MgLayer = CType(layers.GetItem("IMC_ROAD_LINK"),
MgLayer)
        Dim resId As MgResourceIdentifier = New
MgResourceIdentifier(layer.GetFeatureSourceId())
        Dim layerDefResId As MgResourceIdentifier =
layer.GetLayerDefinition()
        Dim byteReader As MgByteReader =
resService.GetResourceContent(layerDefResId)
        Dim doc As New XmlDocument()
        Dim xmlLayerDef As String = byteReader.ToString()
        doc.LoadXml(xmlLayerDef)

        Dim nodeList As XmlNodeList =
doc.GetElementsByTagName("VectorScaleRange")

        Dim vectorScaleRangecElement As XmlElement = CType(nodeList.Item(0),
XmlElement)
        Dim areaTypeStyle As XmlElement =
CType(vectorScaleRangecElement.GetElementsByTagName("LineTypeStyle").Item(0),
XmlElement)


        Dim areaRuleList As XmlNodeList =
areaTypeStyle.GetElementsByTagName("LineRule")
        Dim count As Integer = areaRuleList.Count
        For iq As Integer = 0 To count - 1
            areaTypeStyle.RemoveChild(areaRuleList.Item(0))
        Next
        Dim areaRuleTemplate As String =
File.ReadAllText(GetThemeXmlTemplatePath())
        Dim queryoptions As MgFeatureQueryOptions = New
MgFeatureQueryOptions()
        queryoptions.AddFeatureProperty("LINK_ID")
        queryoptions.SetFilter("LINK_ID =170")
        Dim increment1 As Double = IIf((5 > 1), 1.0 / (5 - 1), 1.0)
        Dim str As String = layer.GetFeatureClassName()

        Dim dataReader1 As MgFeatureReader =
featureService.SelectFeatures(resId, layer.GetFeatureClassName(),
queryoptions)
        While dataReader1.ReadNext()
            value = GetFeaturePropertyValue(dataReader1, "LINK_ID")
            filterText = "&quot;" + "LINK_ID" + "&quot; = "
            filterText = filterText + value
            areaRuleXML = String.Format(areaRuleTemplate, "LINK_ID" + ":" +
value, filterText, InterpolateColor(portion, "00FF00", "00FF00", 0),
InterpolateColor(portion, "00FF00", "00FF00", 0))
            areaDoc = New XmlDocument()
            areaDoc.LoadXml(areaRuleXML)
            areaNode = doc.ImportNode(areaDoc.DocumentElement, True)
            areaTypeStyle.AppendChild(areaNode)
            portion = portion + increment1
        End While
        dataReader1.Close()
        Dim xmlString As String = doc.DocumentElement.OuterXml
      
        Dim layerResId As MgResourceIdentifier = New
MgResourceIdentifier("Session:" + sessionId + "//" + "short path" +
".LayerDefinition")
        resService.SetResource(layerResId, New MgByteReader(xmlString,
"text/xml"), Nothing)

        Dim newLayer As MgLayer = New MgLayer(layerResId, resService)
        Dim legendLabel As String = "Shortest Path"

        newLayer.SetName("Shortest Path")
        newLayer.SetLegendLabel(legendLabel)
        newLayer.SetDisplayInLegend(layer.GetDisplayInLegend())
        newLayer.SetVisible(True)
        newLayer.SetSelectable(layer.GetSelectable())
        layers.Insert(layers.IndexOf(layer), newLayer)
        map.Save(resService)
iam unable to identify the problem

i want to get only a new layer with link_id 170

can anyone plz tell me the solution


regards,
Padmini.


   
-- 
View this message in context: http://n2.nabble.com/select-features-problem-tp2745039p2745039.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list