static void Main(string[] args) { string string_MP = "1010"; double double_MP; //#1 Try to parse the string bool double_parse_worked = System.Double.TryParse(string_MP, out double_MP); if (double_parse_worked) { //#2 Create the locator on line 1 Enbridge.LinearReferencing.ContLineLocatorSQL loc; //#3 run the locator loc = new Enbridge.LinearReferencing.ContLineLocatorSQL("{D4D4472B-FB1E-485B-A550-DCE76F63BC08}"); double stn, meas, X, Y, Z; stn = loc.getStnFromMP(double_MP, out meas, out X, out Y, out Z); Console.WriteLine("{0} {1} {2} {3}", stn, meas, X, Y, Z); } UpdateDLLs.update(); Console.WriteLine("finish"); Console.ReadLine(); }
public bool addFeatureByMP(string routeId, string featureType, string description, double mp) { Enbridge.LinearReferencing.ContLineLocatorSQL loc = new Enbridge.LinearReferencing.ContLineLocatorSQL(routeId); double stn, meas, X, Y, Z; stn = loc.getStnFromMP(mp, out meas, out X, out Y, out Z); string stnSeriesId = loc.getLocation(X, Y); this.pendingFeaturesList.Add(new PointFeat(routeId, stnSeriesId, stn, mp, featureType, Y, X, description, Z)); return true; }
/// <summary> /// Add a point on line 1 given the mile post /// </summary> /// <param name="milePost">Mile Post</param> /// <returns>success status true or false</returns> public bool AddPointByMilePost(double milePost) { if (milePost < 774 || milePost > 1090) { Console.WriteLine("Mile Post out of range for line 1"); return false; } //Create a locator object for Line 1 Enbridge.LinearReferencing.ContLineLocatorSQL loc = new Enbridge.LinearReferencing.ContLineLocatorSQL("{D4D4472B-FB1E-485B-A550-DCE76F63BC08}"); //declare variables to hold return value and out parameters from getStnFromMP double meas, X, Y, Z, stationing; //run the locator stationing = loc.getStnFromMP(milePost, out meas, out X, out Y, out Z); //reassign the pointGeometry to a new instance of PointGeometry, created //using the constructor with parameters this.pointGeometry = new PointGeometry(X, Y, Z, stationing); //Set the geometryValuesAssigned flag to true this.geometryValuesAssigned = true; //set *this* object property milePost to the passed in parameter milePost this.milePost = milePost; return true; }
/// <summary> /// Georeference the plan /// </summary> /// <param name="processHelper">reference to persistant arcobjects</param> public void georefDrawing(DrawingProcessorHelper processHelper) { //Locate the start and end match points by stationing Enbridge.LinearReferencing.ContLineLocatorSQL locator = new Enbridge.LinearReferencing.ContLineLocatorSQL(this.LLId); double startX, startY, startZ, endX, endY, endZ, meas; locator.getMPFromStn(this.MatchStartStn, out meas, out startX, out startY, out startZ); locator.getMPFromStn(this.MatchEndStn, out meas, out endX, out endY, out endZ); //convert long lat coordinates to web mercator double startMercX, startMercY, endMercX, endMercY; Enbridge.Utilities.ProjectionConversion.toWebMercator(startX, startY, out startMercX, out startMercY); Enbridge.Utilities.ProjectionConversion.toWebMercator(endX, endY, out endMercX, out endMercY); //dictionary to hold the mercator xy values mercCoords = new Dictionary<string, double>() { { "startMercX", startMercX }, { "startMercY", startMercY }, { "endMercX", endMercX }, { "endMercY", endMercY } }; //define the projection of the plan to 3857 processHelper.defineProj.in_dataset = pngPlanPath; processHelper.gp.Execute(processHelper.defineProj, null); //open the raster workspace processHelper.rastWorkspace = (ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace)processHelper.workspaceFact.OpenFromFile(Path.GetDirectoryName(pngPlanPath), 0); //open the raster dataset processHelper.rasDataset = processHelper.rastWorkspace.OpenRasterDataset(Path.GetFileName(pngPlanPath)); //open the raster data processHelper.rast = processHelper.rasDataset.CreateDefaultRaster(); //Set location of image source points ESRI.ArcGIS.Geometry.IPoint sourcePoint1 = new ESRI.ArcGIS.Geometry.Point(); sourcePoint1.X = planCoords["X1"]; sourcePoint1.Y = planCoords["Y1"]; processHelper.sourcePoints.UpdatePoint(0, sourcePoint1); ESRI.ArcGIS.Geometry.IPoint sourcePoint2 = new ESRI.ArcGIS.Geometry.Point(); sourcePoint2.X = planCoords["X2"]; sourcePoint2.Y = planCoords["Y2"]; processHelper.sourcePoints.UpdatePoint(1, sourcePoint2); //Set location of target points, that of the stationing match locations ESRI.ArcGIS.Geometry.IPoint targetPoint1 = new ESRI.ArcGIS.Geometry.Point(); targetPoint1.X = mercCoords["startMercX"]; targetPoint1.Y = mercCoords["startMercY"]; processHelper.targetPoints.UpdatePoint(0, targetPoint1); ESRI.ArcGIS.Geometry.IPoint targetPoint2 = new ESRI.ArcGIS.Geometry.Point(); targetPoint2.X = mercCoords["endMercX"]; targetPoint2.Y = mercCoords["endMercY"]; processHelper.targetPoints.UpdatePoint(1, targetPoint2); //complete the georeferencing processHelper.rasterPropc.TwoPointsAdjust(processHelper.sourcePoints, processHelper.targetPoints, processHelper.rast); //save the georeferencing to disk processHelper.rasterPropc.Register(processHelper.rast); }
public UpdateDocPointsSegments(string routeidentifier = null) { docPointsList = new List<DocPoint>(); List<string> routeEventIds = new List<string>(); if (routeidentifier == null) { Console.WriteLine("route id is null"); using (SqlConnection conn = new SqlConnection(AppConstants.CONN_STRING_DOC)) { conn.Open(); SqlCommand comm = conn.CreateCommand(); comm.CommandText = "EXEC sde.set_current_version 'sde.WORKING';"; comm.CommandText += "Select Distinct RouteEventID from sde.DEPTHOFCOVER_EVW WHERE Status='Active';"; try { SqlDataReader reader = comm.ExecuteReader(); while (reader.Read()) { routeEventIds.Add(reader[0].ToString()); } } catch (SqlException ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } } } else { Console.WriteLine("route id not null"); routeEventIds.Add(routeidentifier); } foreach (string id in routeEventIds) { docPointsList.Clear(); string routeId = id.ToUpper(); Console.WriteLine(routeId); using (SqlConnection conn = new SqlConnection(AppConstants.CONN_STRING_DOC)) { conn.Open(); SqlCommand comm = conn.CreateCommand(); comm.CommandText = "EXEC sde.set_current_version 'sde.WORKING';"; comm.CommandText += "Select EventID, CreatedBy, CreatedDate, POINT_X, POINT_Y, POINT_Z, Measurement, "; comm.CommandText += "Description, EquipmentID, Accuracy, Probe, SeriesEventID, Station, Measure, "; comm.CommandText += "RouteEventID, PointGroupID, ModifiedBy "; comm.CommandText += "from sde.DEPTHOFCOVER_EVW "; comm.CommandText += "WHERE Status='Active' AND RouteEventID = @routeId "; comm.CommandText += "Order by Measure ASC;"; comm.Parameters.AddWithValue("routeId", routeId); try { SqlDataReader reader = comm.ExecuteReader(); while (reader.Read()) { docPointsList.Add(new DocPoint(reader)); } } catch (SqlException ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } } UpdatePoints(); this.docPointsList.RemoveAll(isArchive); this.docPointsList.RemoveAll(toRemove); switch (this.docPointsList.Count) { case 0: return; case 1: this.docPointsList[0].segmentStart = this.docPointsList[0].measure - 300; this.docPointsList[0].segmentStop = this.docPointsList[0].measure + 300; break; default: this.docPointsList[0].segmentStart = this.docPointsList[0].measure - 300; this.docPointsList[0].segmentStop = (this.docPointsList[0].measure + this.docPointsList[1].measure) / 2; this.docPointsList[0].segmentStop = ( this.docPointsList[0].segmentStop - this.docPointsList[0].measure > 300 ? this.docPointsList[0].measure + 300 : this.docPointsList[0].segmentStop); for (int i = 1; i < this.docPointsList.Count - 1; i++) { double startMeasure = (this.docPointsList[i - 1].measure + this.docPointsList[i].measure) / 2; startMeasure = (this.docPointsList[i].measure - startMeasure > 300 ? this.docPointsList[i].measure - 300 : startMeasure); this.docPointsList[i].segmentStart = startMeasure; double endMeasure = (this.docPointsList[i].measure + this.docPointsList[i + 1].measure) / 2; endMeasure = (endMeasure - this.docPointsList[i].measure > 300 ? this.docPointsList[i].measure + 300 : endMeasure); this.docPointsList[i].segmentStop = endMeasure; } this.docPointsList[this.docPointsList.Count - 1].segmentStart = (this.docPointsList[this.docPointsList.Count - 1].measure + this.docPointsList[this.docPointsList.Count - 2].measure) / 2; this.docPointsList[this.docPointsList.Count - 1].segmentStart = (this.docPointsList[this.docPointsList.Count - 1].measure - this.docPointsList[this.docPointsList.Count - 1].segmentStart > 300 ? this.docPointsList[this.docPointsList.Count - 1].measure - 300 : this.docPointsList[this.docPointsList.Count - 1].segmentStart); this.docPointsList[this.docPointsList.Count - 1].segmentStop = this.docPointsList[this.docPointsList.Count - 1].measure + 300; break; } Enbridge.LinearReferencing.ContLineLocatorSQL locator = new Enbridge.LinearReferencing.ContLineLocatorSQL(routeId); double minMeasure = locator.pointList[0].meas; double maxMeasure = locator.pointList[locator.pointList.Count - 1].meas; List<DocSegment> segmentList = new List<DocSegment>(); for (int i = 0; i < this.docPointsList.Count; i++) { //Console.WriteLine("{0} {1} {2}", segList[i][0], segList[i][1], segList[i][2]); this.docPointsList[i].segmentStart = (this.docPointsList[i].segmentStart < minMeasure ? minMeasure : this.docPointsList[i].segmentStart); this.docPointsList[i].segmentStop = (this.docPointsList[i].segmentStop > maxMeasure ? maxMeasure : this.docPointsList[i].segmentStop); double startStn, endStn; //Console.WriteLine("__{0}, {1}", this.docPointsList[i].segmentStart, this.docPointsList[i].segmentStop); string geomString = locator.makeSegmentLineString(this.docPointsList[i].segmentStart, this.docPointsList[i].segmentStop, out startStn, out endStn); DocSegment seg = new DocSegment(geomString, startStn, endStn, this.docPointsList[i].seriesEventId, this.docPointsList[i].measurement, this.docPointsList[i].eventID, routeId); segmentList.Add(seg); } using (SqlConnection conn = new SqlConnection(AppConstants.CONN_STRING_DOC)) { conn.Open(); SqlCommand comm = conn.CreateCommand(); string commandInit = "EXEC sde.set_current_version 'sde.WORKING';"; commandInit += "EXEC sde.edit_version 'sde.working', 1;"; commandInit += "begin transaction;"; comm.CommandText = commandInit; comm.CommandText += "DELETE from sde.depthofcoversegments_evw where routeeventid = @routeid or routeeventid is null;"; string commandEnd = "COMMIT;"; commandEnd += "EXEC sde.edit_version 'sde.WORKING', 2;"; comm.CommandText += commandEnd; comm.Parameters.AddWithValue("@routeid", routeId); try { comm.ExecuteNonQuery(); comm.Parameters.Clear(); comm.CommandText = commandInit; int counter = 0; for (int i = 0; i < segmentList.Count; i++) { string commandString = "INSERT INTO sde.depthofcoversegments_evw "; commandString += "("; commandString += "shape, startstationing, endstationing, eventid, origineventid, "; commandString += "CreatedBy, ModifiedBy, "; //commandString += ", createddate, lastmodified, "; commandString += "serieseventid, measurement, pointeventid, routeeventid"; commandString += ") "; commandString += "VALUES "; commandString += segmentList[i].ToString(); commandString += ";"; comm.CommandText += commandString; counter++; if (counter > 50 || i == segmentList.Count - 1) { comm.CommandText += commandEnd; comm.ExecuteNonQuery(); Console.WriteLine("segments in"); comm.CommandText = commandInit; counter = 0; } } Console.WriteLine("success"); } catch (SqlException ex) { Console.WriteLine(ex.Message); } finally { comm.Dispose(); conn.Close(); Console.WriteLine("exited"); } } } }
/// <summary> /// Input Depth of Cover table object constructor /// </summary> /// <param name="inputString"></param> /// <param name="lineLoopEventId"></param> /// <param name="groupDescription"></param> public InputDOCTable(string inputString, string lineLoopEventId, string groupDescription, string username) { this.pointGroupId = "{" + Guid.NewGuid().ToString().ToUpper() + "}"; this.routeEventId = "{" + lineLoopEventId.ToUpper() + "}"; this.routeName = Enbridge.AppConstants.GetLineName(this.routeEventId); this.groupDescription = groupDescription; this.groupCreatedDate = DateTime.Now; this.username = username; extent = new Dictionary<string, double>{ {"xMin", 10E100}, {"xMax", -10E100}, {"yMin", 10E100}, {"yMax", -10E100} }; string[] lines = inputString.Split('\n'); for (int i = 1; i < lines.Length; i++) { string lineContent = lines[i]; if (lineContent.Replace(",","").Trim() == "") { //Empty row detected break; } string[] rowCells = lineContent.Split(','); for (int j = 0; j < rowCells.Length; j++) { rowCells[j] = rowCells[j].Trim(); } //Get created by text string createdBy = rowCells[0]; //get and validate the date DateTime createdDate; if (!DateTime.TryParse(rowCells[1], out createdDate)){ validationError = string.Format("Date format invalid, {0} in record# {1}", rowCells[1], i); return; } //Get and validate the x, y and z values double X, Y; if (!Double.TryParse(rowCells[2], out X)) { validationError = string.Format("POINT_X format invalid, {0} in record# {1}", rowCells[2], i); return; } if (!Double.TryParse(rowCells[3], out Y)) { validationError = string.Format("POINT_Y format invalid, {0} in record# {1}", rowCells[3], i); return; } double? Z_null = null; double Z; if (rowCells[4] != "") { if (!Double.TryParse(rowCells[4], out Z)) { validationError = string.Format("POINT_Z format invalid, {0} in record# {1}", rowCells[4], i); return; } Z_null = Z; } double measurement; if (!Double.TryParse(rowCells[5], out measurement)) { validationError = string.Format("Measurement format invalid, {0} in record# {1}", rowCells[5], i); return; } int? equipIdNull = null; int equipId; string description = rowCells[6]; if (rowCells[7] != "") { if (!int.TryParse(rowCells[7], out equipId)) { validationError = string.Format("Equipment Id format invalid, {0} in record# {1}", rowCells[7], i); return; } equipIdNull = equipId; } double? accuracyNull = null; double accuracy; if (rowCells[8] != "") { if (!Double.TryParse(rowCells[8], out accuracy)) { validationError = string.Format("Accuracy format invalid, {0} in record# {1}", rowCells[8], i); return; } accuracyNull = accuracy; } bool? probe = null; if (rowCells[9] != "") { switch (rowCells[9]) { case "0": probe = false; break; case "1": probe = true; break; default: validationError = string.Format("Probe format invalid, {0} in record# {1}", rowCells[9], i); return; } } this.AddDOCRecord(createdBy, createdDate, X, Y, Z_null, measurement, description, equipIdNull, accuracyNull, probe); } if (this.validationError == null) { Enbridge.LinearReferencing.ContLineLocatorSQL locator = new Enbridge.LinearReferencing.ContLineLocatorSQL(lineLoopEventId); for (int i = 0; i < this.docPointList.Count; i++) { double stn, meas, mp; string stnSeriesEventId = locator.getLocation(docPointList[i].point_X, docPointList[i].point_Y, out stn, out meas, out mp); docPointList[i].seriesEventId = stnSeriesEventId; docPointList[i].station = stn; docPointList[i].measure = meas; docPointList[i].pointGroupId = this.pointGroupId; docPointList[i].routeEventId = this.routeEventId; docPointList[i].groupCreatedDate = this.groupCreatedDate; this.docGraphicList.Add(docPointList[i].toGraphic()); } } }