Created
May 6, 2013 04:27
-
-
Save dbouwman/5523346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//NOTE THIS IS A SNIPPET OF CODE! IT WILL NOT RUN LIKE THIS! STUFF IT INTO A CLASS | |
IFeatureClass featureClass = Helper.OpenFromFGDB(@"C:\data\Historical_Routes.gdb", fcName); | |
Type t = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment"); | |
System.Object obj = Activator.CreateInstance(t); | |
ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory; | |
IProjectedCoordinateSystem webMercatorSR = srFact.CreateProjectedCoordinateSystem((int)esriSRProjCS2Type.esriSRProjCS_WGS1984SphereWebMercator); | |
IQueryFilter queryFilter = new QueryFilterClass(); | |
queryFilter.WhereClause = string.Format("{0} LIKE '{1}'", "ROUTE", route); | |
queryFilter.set_OutputSpatialReference(featureClass.ShapeFieldName, webMercatorSR); | |
// Get the feature cursor | |
IFeatureCursor featureCursor = featureClass.Search(queryFilter, false); | |
IFeature routeFeature = featureCursor.NextFeature(); | |
if (routeFeature != null) //we should do a tight loop here | |
{ | |
foreach (dynamic row in rows) //this is my "batch" of inbound data, all on the same route | |
{ | |
//parse out the data from the Massive dynamic object | |
double refpt = double.Parse(row.REFPOINT.ToString()); | |
long id = long.Parse(row.ID.ToString()); | |
string hwy = row.ROUTENAME.ToString(); | |
//I also ordered the inbound data by the refpoint. Many times there are multiple cameras and the | |
//photos are taken at the same refpt, so we can re-use the data to save a few lookups | |
if (LastResult != null && LastResult.ROUTENAME == hwy && LastResult.REFPOINT == refpt) | |
{ | |
string err = LastResult.ERRORMESSAGE; | |
LastResult = new DynSegResult(id, hwy, refpt, LastResult.x, LastResult.y); | |
LastResult.ERRORMESSAGE = err; //pass the error forward b/c this could be a dupe refpt of an error | |
dupeCt++; | |
} | |
else | |
{ | |
//this is the actual lookup of the measure | |
IMSegmentation segmentation = routeFeature.Shape as IMSegmentation; | |
IGeometryCollection geometryCollection = segmentation.GetPointsAtM(refpt, 0); | |
IPointCollection pointCollection = geometryCollection as IPointCollection; | |
//check that we got something in our point collection | |
if (pointCollection != null && pointCollection.PointCount > 0) | |
{ | |
IPoint point = pointCollection.get_Point(0); | |
LastResult = new DynSegResult(id, hwy, refpt, point.X, point.Y); | |
} | |
else | |
{ | |
var err = "Could not locate " + refpt.ToString() + " on route " + hwy; | |
LastResult = new DynSegResult(id, hwy, refpt, err); | |
} | |
//dispose stuff used in the tight loop... | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(segmentation); | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(geometryCollection); | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(pointCollection); | |
dsCt++;//increment a counter | |
} | |
batch.Add(LastResult);//add to the results batch | |
} | |
//done the batch, dispose the feature and feature class | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(routeFeature); | |
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); | |
//toss the batch of results to a function that stores them in SQL | |
SaveBatch(batch, year); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment