Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Details(string countryCode, string stateCode, string countyCode, string postalCode, int radius, string featureClass, string featureCode)
- {
- GeonameEntities db = new GeonameEntities();
- RawPostal postal =
- db.RawPostals.FirstOrDefault(p => p.countryCode == countryCode && p.admin1code == stateCode && p.admin2code == countyCode && p.postalCode == postalCode);
- if (postal == null || postal.latitude == null || postal.longitude == null)
- {
- return HttpNotFound();
- }
- int radiusMeters = radius * 1609;
- DbGeography posBuffer = postal.geog.Buffer(radiusMeters);
- DbGeography negBuffer = postal.geog.Buffer(-radiusMeters);
- DbGeography difference = posBuffer.Difference(negBuffer);
- List<RawData> results = db.RawDatas.Where(p => p.featureClass == featureClass && p.featureCode == featureCode && p.geog.Intersects(difference)).OrderBy(o => o.asciiName).ToList();
- double north = (results.Max(p => p.latitude) ?? 0); // North
- double east = (results.Max(p => p.longitude) ?? 0); // East
- double south = (results.Min(p => p.latitude) ?? 0); // South
- double west = (results.Min(p => p.longitude) ?? 0); // West
- double latAngle = north - south; // Latitude Angle
- double longAngle = east - west; // Longitude Angle
- double centerLat = north - latAngle; // Center Latitude
- double centerLong = east - longAngle; // Center Longitude
- if (longAngle < 0)
- {
- longAngle += 360;
- }
- if (latAngle < 0)
- {
- latAngle += 360;
- }
- DaveDetail model = new DaveDetail
- {
- Latitude = (double)postal.latitude,
- Longitude = (double)postal.longitude,
- LatitudeAngle = latAngle,
- LongitudeAngle = longAngle,
- CenterLatitude = centerLat,
- CenterLongitude = centerLong,
- North = north,
- East = east,
- South = south,
- West = west,
- Zoom = radius,
- Pins = results
- };
- return View(model);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement