[mapguide-users] SelectFeatures using SetFilter gives null exception

Tony techswami at hotmail.com
Fri Aug 22 19:24:21 EDT 2008


thanks 

change the code still i am not getting the values  result set is empty any
ideas
if i do the selection and use this code i get a value but if i am searching
it does not work 
by the way if you have idea how to find the features and display them on the
map please let me know 

i want to search for all the pipes that are greater than 12' and show them
on the map 

Tony 


     MgUserInformation userInfo = new MgUserInformation(mgSessionId);
            MgSiteConnection siteConnection = new MgSiteConnection();
            siteConnection.Open(userInfo);

            MgResourceService resourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
            MgFeatureService featureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
            
            MgFeatureQueryOptions districtQuery = new
MgFeatureQueryOptions();
            districtQuery.SetFilter("size> 12");
            
            MgMap map = new MgMap();
            map.Open(resourceService, "General Public Map");
            MgLayer layer = map.GetLayers().GetItem("SD_MAINS") as MgLayer;
            String layerClassName = layer.GetFeatureClassName();

            String layerFeatureIdString = layer.GetFeatureSourceId();
            MgResourceIdentifier districtId = new
MgResourceIdentifier(layerFeatureIdString);
            
            MgFeatureReader featureReader =
featureService.SelectFeatures(districtId, layerClassName, districtQuery);
            featureReader.ReadNext();
            string ss;
            ss =
featureReader.GetClassDefinition().GetDefaultGeometryPropertyName();
            MgByteReader geometryBytes =
featureReader.GetGeometry("Geometry");
            MgAgfReaderWriter agfReader = new MgAgfReaderWriter();
            MgGeometry districtGeometry = agfReader.Read(geometryBytes);
            ArrayList  listEQ = new ArrayList();
            while (featureReader.ReadNext())
            {
                listEQ.Add(featureReader.GetString("MATERIAL"));
                string gg = listEQ[0].ToString();
                Response.Write(gg);
            }
            featureReader.Close();
            featureReader.Dispose();



Jackie Ng wrote:
> 
> I see nothing indicating what feature class you are querying from. The
> fact that you are calling SelectFeatures() from the MgLayer instead of the
> MgFeatureService means that you need to new the MgMap object with the
> MgSiteConnection as indicated here:
> http://trac.osgeo.org/mapguide/wiki/MapGuideRfc9
> 
> - Jackie
> 
> 
> Tony wrote:
>> 
>> Hi 
>> i am using the following code to find the   Pipes that are greater than
>> 12'  i am getting null exeception 
>> the sample code in dev guide is the same. why i am getting error
>> anyone
>> 
>> thanks
>> tony
>> 
>> MgUserInformation userInfo = new MgUserInformation(mgSessionId);
>>             MgSiteConnection siteConnection = new MgSiteConnection();
>>             siteConnection.Open(userInfo);
>> 
>>             MgResourceService resourceService =
>> siteConnection.CreateService(MgServiceType.ResourceService) as
>> MgResourceService;
>>             MgFeatureService featureService =
>> siteConnection.CreateService(MgServiceType.FeatureService) as
>> MgFeatureService;
>>             
>>             MgFeatureQueryOptions districtQuery = new
>> MgFeatureQueryOptions();
>>             districtQuery.SetFilter("Size > 12");
>>             
>>             MgMap map = new MgMap();
>>             map.Open(resourceService, "General Public Map");
>>             MgLayer layer = map.GetLayers().GetItem("SD") as MgLayer;
>>            
>>             MgFeatureReader featureReader =
>> layer.SelectFeatures(districtQuery);
>> //getting error here 
>>             featureReader.ReadNext();
>>             
>>             MgByteReader districtGeometryData =
>> featureReader.GetGeometry("Geometry");
>>             MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
>>             MgGeometry districtGeometry =
>> agfReaderWriter.Read(districtGeometryData);
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/SelectFeatures-using-SetFilter-gives-null-exception-tp777204p777304.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list