Trying to Select Parcels from a MapServer with a SpatialQuery with an ArcMap 10.00

724
2
04-05-2012 08:44 AM
MargoBlosser
New Contributor
I am accessing a  MapServer that has a parcel layer that I am trying to select taxlots with a both a spatial query and an attribute query.  I am accessing the MapServer with a url and am not part of the user AGSusers or Admin groups.

The spatial query is based on a local shape file. Seems simple enough but I get the following error message from  Fiddler:

???Layer not found.7>5 y??H??V?~? "esriCarto.MapServer???

The local shape file and the MapServer layer are both in the same projection.

I am accessing the Mapsever with an IAGSServerConnection Connection.  Code is below:


Dim connectionProperties As IPropertySet = New PropertySetClass()
connectionProperties.SetProperty("Url", "http://www3.multco.us/ArcGIS/Services")
Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriGISClient.AGSServerConnectionFactory"))

Dim PEnumSoName As IAGSEnumServerObjectName = AGSServerConnection.ServerObjectNames

            Dim pSOName As IAGSServerObjectName = PEnumSoName.Next
            PEnumSoName = AGSServerConnection.ServerObjectNames

            Do Until pSOName Is Nothing
                If pSOName.Name = "BaseMap/Taxlots" Then Exit Do              

                pSOName = PEnumSoName.Next
            Loop

            If pSOName Is Nothing Then Exit Sub
           
            pName = pSOName
            pMapServer = pName.Open

          

            Dim pMapServerInfo As IMapServerInfo = pMapServer.GetServerInfo(pMapServer.DefaultMapName)
            Dim pMD As IMapDescription = pMapServerInfo.DefaultMapDescription

?????????????????????????????????????????????????????????????????????????????????????????????????????????Add Mapserver layer to Toc???????????????????????????????????????????????????????????????

pMSLayer.ServerConnect(pSOName, pMapServer.DefaultMapName)

            'Add layer to map
           t pMap = mxDocument.FocusMap
            pAV = pMap
            pMap.AddLayer(pMSLayer)
            pAV.Refresh()

????????????????????????????????????????????????????????????????????????Create Spatial Filiter with Attribute query????????????????????????????????????????????????????????????????????????

Dim pSpatialFilter As ISpatialFilter = New SpatialFilter()
          

            pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin
           

            Dim sabFeatClass As IFeatureClass = featureLayer.FeatureClass
            Dim sabfeature As IFeature = sabFeatClass.GetFeature(0)

            pSpatialFilter.Geometry = sabfeature.Shape
            pSpatialFilter.GeometryField = sabFeatClass.ShapeFieldName
            pSpatialFilter.WhereClause = "NAME LIKE" + Space(1) + "'" + "UNITED" + "%" + "'"

Dim QRecSet As IRecordSet = pMapServer.QueryFeatureData(pMD.Name, 0, pSpatialFilter) ???Code fails here

            Dim Reccursor As ICursor = QRecSet.Cursor(True)
            Dim row As IRow = Nothing

            Dim Feature As IFeature = Reccursor.NextRow
            While (Feature) IsNot Nothing
                Dim Geometry As IGeometry = Feature.Shape

                    ??????do some stuff??????.

                Feature = Reccursor.NextRow
            End While


How should I be creating the spatial filter? Do I have to create it with a servercontext, 

ISpatialFilter pSpatialFilter = pServerContext.CreateObject(
    "esriGeodatabase.SpatialFilter")as ISpatialFilter;

If I need to create the spatial filter with a ServerContext does anyone have some code that shows doing this with a URL?

Should I be doing something to specify that the Spatial Filter is based on a local shape file?


Should I be using a different type of connection, possibly with the ESRI.ARCGIS.ADF.Connection.AGS Namespace?

Can someone point me in the right direction?

Thanks in advance for any guidance that you can provide.

Best Regards,

Margo
0 Kudos
2 Replies
KevinBupp
New Contributor III
Margo:

I put together a quick Console Application to test your MapServer Spatial Query.  I was able to get it to work with the following code ... (I apologize that it is in C# instead of VB.NET ... I can convert it if necessary)
            IPropertySet connProps = new PropertySet();
            connProps.SetProperty("Url", "http://www3.multco.us/ArcGIS/Services");
            AGSServerConnectionFactory agsSCFac = new AGSServerConnectionFactory();
            IAGSServerConnection agsSConn = agsSCFac.Open(connProps, 0);

            IAGSEnumServerObjectName pEnum = agsSConn.ServerObjectNames;
            IAGSServerObjectName pSOName = pEnum.Next();
            while (pSOName != null)
            {
                Console.WriteLine(pSOName.Name);
                if (pSOName.Name.Equals("BaseMap/Taxlots")) break;
                pSOName = pEnum.Next();
            }

            if (pSOName != null)
            {
                IName pName = pSOName as IName;
                IMapServer pMapServer = pName.Open();
                IMapServerInfo pMapServerInfo = pMapServer.GetServerInfo(pMapServer.DefaultMapName);
                IMapDescription pMD = pMapServerInfo.DefaultMapDescription;

                IPoint pnt = new Point();
                pnt.SpatialReference = pMD.SpatialReference;
                pnt.PutCoords(7682600.809, 681343.674);

                ISpatialFilter pSpatFilter = new SpatialFilter();
                pSpatFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                pSpatFilter.Geometry = pnt;
                pSpatFilter.WhereClause = "PROPID = 'R311157'";

                IRecordSet records = pMapServer.QueryFeatureData(pMD.Name, 0, pSpatFilter);
                Console.WriteLine("Found " + records.Table.RowCount(null) + " records");

                ICursor pCur = records.get_Cursor(true);
                IFeature pFeat = pCur.NextRow() as IFeature;
                if (pFeat != null)
                {
                    Console.WriteLine("SUCCESS! Found Property: " + pFeat.Value[pFeat.Fields.FindField("PROPID")]);
                }
            }


That means that your map service is fine, and that there is something wrong in the implementation ... In my code above, I used a Point that I created instead of a Feature from a Layer in a Map.  That might be where your problem lies ...

Hope this helps,
-Kevin
MargoBlosser
New Contributor
Kevin,

Thank you for the test code, it really helped.  I used your code and the query worked, so it appeared that I was going in the right direction.  After fiddling around with my orginal code it turned out to be the pSpatialFilter.GeometryField = sabFeatureClass.ShapeFieldName code that was hanging things up.  Crazy that this would make the difference, but the spatial query is now just working fine.

Thanks again!

Margo Blosser
Gorge GIS
www.gorgegis.com
www.interactivegeospatial.com
0 Kudos