예제 #1
0
        public static TigerLookupAllData LookupAll(double latitude, double longitude)
        {
            var result = new TigerLookupAllData();

            lock (ShapeFile.Sync)
            {
                var countyIndex = CountyShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (countyIndex < 0)
                {
                    return(result);
                }
                var countyValues = CountyShapeFile.GetAttributeFieldValues(countyIndex);
                result.Fips      = countyValues[0].Trim();
                result.StateCode = StateCache.StateCodeFromLdsStateCode(result.Fips);
                result.County    = countyValues[1].Trim();

                var congressIndex =
                    CongressShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (congressIndex >= 0)
                {
                    var congressValues = CongressShapeFile.GetAttributeFieldValues(congressIndex);
                    result.Congress = Translate(TableTypeCongressionalDistrict, result.StateCode,
                                                congressValues[1].Trim());
                }

                var upperIndex = UpperShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (upperIndex >= 0)
                {
                    var upperValues = UpperShapeFile.GetAttributeFieldValues(upperIndex);
                    result.Upper = Translate(TableTypeStateSenate, result.StateCode,
                                             upperValues[1].Trim());
                }

                var lowerIndex = LowerShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (lowerIndex >= 0)
                {
                    var lowerValues = LowerShapeFile.GetAttributeFieldValues(lowerIndex);
                    result.Lower = Translate(TableTypeStateHouse, result.StateCode,
                                             lowerValues[1].Trim());
                }

                var districtIndex =
                    DistrictShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (districtIndex >= 0)
                {
                    var districtValues = DistrictShapeFile.GetAttributeFieldValues(districtIndex);
                    result.District         = districtValues[2].Trim();
                    result.DistrictName     = districtValues[5].Trim();
                    result.DistrictLongName = districtValues[6].Trim();
                }

                var placeIndex =
                    PlaceShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (placeIndex >= 0)
                {
                    var placeValues = PlaceShapeFile.GetAttributeFieldValues(placeIndex);
                    result.Place         = placeValues[1].Trim();
                    result.PlaceName     = placeValues[4].Trim();
                    result.PlaceLongName = placeValues[5].Trim();
                }

                var elementaryIndex =
                    ElementaryShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (elementaryIndex >= 0)
                {
                    var elementaryValues = ElementaryShapeFile.GetAttributeFieldValues(elementaryIndex);
                    result.Elementary     = elementaryValues[1].Trim();
                    result.ElementaryName = elementaryValues[3].Trim();
                }

                var secondaryIndex =
                    SecondaryShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (secondaryIndex >= 0)
                {
                    var secondaryValues = SecondaryShapeFile.GetAttributeFieldValues(secondaryIndex);
                    result.Secondary     = secondaryValues[1].Trim();
                    result.SecondaryName = secondaryValues[3].Trim();
                }

                var unifiedIndex = UnifiedShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (unifiedIndex >= 0)
                {
                    var unifiedValues = UnifiedShapeFile.GetAttributeFieldValues(unifiedIndex);
                    result.Unified     = unifiedValues[1].Trim();
                    result.UnifiedName = unifiedValues[3].Trim();
                }

                var cityCouncilIndex = CityCouncilShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (cityCouncilIndex >= 0)
                {
                    var cityCouncilValues = CityCouncilShapeFile.GetAttributeFieldValues(cityCouncilIndex);
                    result.CityCouncil         = cityCouncilValues[1].Trim();
                    result.CityCouncilDistrict = cityCouncilValues[3].Trim();
                }

                var countySupervisorsIndex = CountySupervisorsShapeFile.GetShapeIndexContainingPoint(new PointD(longitude, latitude), 0.0);
                if (countySupervisorsIndex >= 0)
                {
                    var countySupervisorsValues = CountySupervisorsShapeFile.GetAttributeFieldValues(countySupervisorsIndex);
                    result.CountySupervisors         = countySupervisorsValues[2].Trim();
                    result.CountySupervisorsDistrict = countySupervisorsValues[3].Trim();
                }
            }
            return(result);
        }