ThinkGeo.com    |     Documentation    |     Premium Support

QueryTools.GetFeaturesByColumnValue issue!

Hi I try to use QueryTools.GetFeaturesByColumnValue but I get an exception..... When looking in debug mode it seems that


the shapefilefeaturelayer is open but I cannot see any column....


thanks.


jm


 



  private static ShapeFileFeatureLayer STATES;

        private static ShapeFileFeatureLayer ZIP3;

        private static ShapeFileFeatureLayer ZIP5;

        private static ShapeFileFeatureLayer COUNTY;



        private static FeatureCache featureCache_DataSource_STATES;

        private static FeatureCache featureCache_DataSource_ZIP3;

        private static FeatureCache featureCache_DataSource_ZIP5;

        private static FeatureCache featureCache_DataSource_COUNTY;



        private static Collection<Feature> _spq_ZIP5;

        private static Collection<Feature> _spq_ZIP3;

        private static Collection<Feature> _spq_STATES;

        private static Collection<Feature> _spq_COUNTY;



        public void GeoRelationshipsOpen(string SERVER_ICON_LIBRARY_DRIVE, string SERVER_RAM_DRIVE, string SERVER_RAM_DRIVE_CACHE_PATH)

        {



            featureCache_DataSource_STATES = new FeatureCache();

            featureCache_DataSource_ZIP3 = new FeatureCache();

            featureCache_DataSource_ZIP5 = new FeatureCache();

            featureCache_DataSource_COUNTY = new FeatureCache();



            featureCache_DataSource_STATES.IsActive = true;

            featureCache_DataSource_ZIP3.IsActive = true;

            featureCache_DataSource_ZIP5.IsActive = true;

            featureCache_DataSource_COUNTY.IsActive = true;



            ShapeFileFeatureLayer.BuildIndexFile(SERVER_RAM_DRIVE + @"\USCENSUS\US_STATES\tl_2010_us_state10.shp", BuildIndexMode.DoNotRebuild);

            STATES = new ShapeFileFeatureLayer(SERVER_RAM_DRIVE + @"\USCENSUS\US_STATES\tl_2010_us_state10.shp", ShapeFileReadWriteMode.ReadOnly);

            STATES.Name = "STATES";

            STATES.FeatureSource.GeoCache = featureCache_DataSource_STATES;

            STATES.FeatureSource.GeoCache.IsActive = true;

            STATES.FeatureSource.Open();



            ShapeFileFeatureLayer.BuildIndexFile(SERVER_RAM_DRIVE + @"\USCENSUS\US_ZIPCODES_3\z399_d00.shp", BuildIndexMode.DoNotRebuild);

            ZIP3 = new ShapeFileFeatureLayer(SERVER_RAM_DRIVE + @"\USCENSUS\US_ZIPCODES_3\z399_d00.shp", ShapeFileReadWriteMode.ReadOnly);

            ZIP3.Name = "ZIP3";

            ZIP3.FeatureSource.GeoCache = featureCache_DataSource_STATES;

            ZIP3.FeatureSource.GeoCache.IsActive = true;

            ZIP3.FeatureSource.Open();



            ShapeFileFeatureLayer.BuildIndexFile(SERVER_RAM_DRIVE + @"\USCENSUS\US_ZIPCODES_5\tl_2010_us_zcta510.shp", BuildIndexMode.DoNotRebuild);

            ZIP5 = new ShapeFileFeatureLayer(SERVER_RAM_DRIVE + @"\USCENSUS\US_ZIPCODES_5\tl_2010_us_zcta510.shp", ShapeFileReadWriteMode.ReadOnly);

            ZIP5.Name = "ZIP5";

            ZIP5.FeatureSource.GeoCache = featureCache_DataSource_STATES;

            ZIP5.FeatureSource.GeoCache.IsActive = true;

            ZIP5.FeatureSource.Open();



            ShapeFileFeatureLayer.BuildIndexFile(SERVER_RAM_DRIVE + @"\USCENSUS\US_COUNTY\tl_2011_us_county.shp", BuildIndexMode.DoNotRebuild);

            COUNTY = new ShapeFileFeatureLayer(SERVER_RAM_DRIVE + @"\USCENSUS\US_COUNTY\tl_2011_us_county.shp", ShapeFileReadWriteMode.ReadOnly);

            COUNTY.Name = "COUNTY";

            COUNTY.FeatureSource.GeoCache = featureCache_DataSource_COUNTY;

            COUNTY.FeatureSource.GeoCache.IsActive = true;

            COUNTY.FeatureSource.Open();

        }

        public object GeoRelationships(string gkey, string gvalue)

        {

            _spq_ZIP5 = new Collection<Feature>();

            _spq_ZIP3 = new Collection<Feature>();

            _spq_STATES = new Collection<Feature>();

            _spq_COUNTY = new Collection<Feature>();



            GeoRelationShips _gr = new GeoRelationShips();



            Collection<FeatureSourceColumn> _fc = ZIP5.FeatureSource.GetColumns();



            _spq_ZIP5 = ZIP5.QueryTools.GetFeaturesByColumnValue(gkey, gvalue);

            _spq_STATES = STATES.QueryTools.GetFeaturesContaining(_spq_ZIP5[0], ReturningColumnsType.AllColumns);

            _spq_ZIP3 = ZIP3.QueryTools.GetFeaturesContaining(_spq_ZIP5[0], ReturningColumnsType.AllColumns);

            _spq_COUNTY = COUNTY.QueryTools.GetFeaturesContaining(_spq_ZIP5[0], ReturningColumnsType.AllColumns);



            _gr._geoid_ZIP5_WKT = _spq_ZIP5[0].GetShape().GetCenterPoint().GetWellKnownText();

            _gr._geoid_STATE_WKT = _spq_STATES[0].GetShape().GetCenterPoint().GetWellKnownText();

            _gr._geoid_ZIP3_WKT = _spq_ZIP3[0].GetShape().GetCenterPoint().GetWellKnownText();

            _gr._geoid_COUNTY_WKT = _spq_COUNTY[0].GetShape().GetCenterPoint().GetWellKnownText();



            _gr._geoid_ZIP5 = _spq_ZIP5[0].ColumnValues["GEOID10"];

            _gr._geoid_ZIP3 = _spq_ZIP3[0].ColumnValues["ZCTA3"];

            _gr._geoid_STATES = _spq_STATES[0].ColumnValues["GEOID10"];

            _gr._geoid_COUNTY = _spq_COUNTY[0].ColumnValues["GEOID"];



            return (_gr);

        }

        public void GeoRelationshipsClose()

        {

            STATES.FeatureSource.Close();

            ZIP3.FeatureSource.Close();

            ZIP5.FeatureSource.Close();

            COUNTY.FeatureSource.Close();

        }



 




 


 



Jean-Marie,


 Could you send us the shapefile you are having problem with? Or if you already sent it to us, what is its name? With what column do you get the exception? Thank you for giving us a little more specifics on this issue.



Hello,


yes I have an issue with the shapefile from the US Census bureau  (tl_2010_us_state10.shp) that you can download from their web site.  I can use the shapefile for everything else but the "GetFeaturesByColumnValue"...  "GetFeaturesByColumnValue" work well when used with an in memory feature layer.  The exception I get is about a "NullReferenceException occurred use the new keyword to create an object instance".   Based on what I can see all of my objects seems to be created. 


System.NullReferenceException occurred

  Message=Object reference not set to an instance of an object.

  Source=THKGEOTools

  StackTrace:

       at THKGEOTools.ThkGeoTools.GeoRelationships(String gkey, String gvalue) in C:\Users\a09zmzz\Documents\Visual Studio 2010\Projects\GeoSpatial\THKGEOTools\ThkGeoTools.cs:line 587

  InnerException:


 


I was unable to pinpoint from where this is comming from.......


 


thanks for your support.


 


jm

 


 



Jean-Marie,


 Can you give us the exact link on where to get that shapefile (tl_2010_us_state10.shp)? I did some search on the US Census bureau site; I was not too lucky. Thank you.



census.gov/cgi-bin/geo/shapefiles2010/layers.cgi

Jean-Marie,


 With the link you gave me I still don't know where to get that tl_2010_us_state10.shp. That is just a shapefile name, I don't know what is represents. I don't know where to go to download it. Be more specific, please. Thank you.




Hi, 
  
 you have to go to the US Census web site then you have to download from the web site: 
  
 census.gov/geo/www/tiger/shp.html 
  
 thx

Jean Marie,


 I understand that but there are many shapefiles to download. In what category is it? In what state? I cannot know where to go exactely just based on the name of your shapefile tl_2010_us_state10.shp. Thank you.