ThinkGeo.com    |     Documentation    |     Premium Support

Replace LINESTRING coordinate pair with POINT coordinate pair

I am attempting to conjure up a potion that will let me replace a coordinate pair of a LINESTRING with a coordinate pair of a Point.



LINESTRING(-96.53140902 31.70302971,-96.53304535 31.70499253)

POINT(-96.5329705463785 31.7049028011285)

My result would be LINESTRING(-96.5329705463785 31.7049028011285,-96.53304535 31.70499253)



foundlines.EditTools.BeginTransaction()
For As Integer = 0 To searchResults.Count - 1
  myfeature = searchResults(i)
  Dim myLine As New LineShape(myfeature.GetShape().GetWellKnownText())
  StartGORD = Convert.ToDouble(myfeature.ColumnValues("GORD"))
  If StartXY.Contains(StartGORD) Then
    '''GetWellKnownText for LINESTRING AND POINT
    '''potion for starting coordinate pair replace
  End If
  If EndXY.Contains(StartGORD) Then
    '''GetWellKnownText for LINESTRING AND POINT
    '''potion for ending coordinate pair replace
  End If
  foundlines.EditTools.Add(myfeature)
Next i
foundlines.EditTools.CommitTransaction()

Thanks



Hi Craig, 
  
 As below code shows how to update vertex in feature, wish it’s helpful for you. 
  
  // Replace start point of each line in layer to 0,0

                InMemoryFeatureLayer layer = new InMemoryFeatureLayer();

                LineShape line1 = new LineShape(new Collection<Vertex>() { new Vertex(1, 1), new Vertex(10, 10) });
                LineShape line2 = new LineShape(new Collection<Vertex>() { new Vertex(1, 1), new Vertex(-10, -10) });
                LineShape line3 = new LineShape(new Collection<Vertex>() { new Vertex(1, 1), new Vertex(10, -10) });
                LineShape line4 = new LineShape(new Collection<Vertex>() { new Vertex(1, 1), new Vertex(-10, 10) });

                layer.InternalFeatures.Add(new Feature(line1));
                layer.InternalFeatures.Add(new Feature(line2));
                layer.InternalFeatures.Add(new Feature(line3));
                layer.InternalFeatures.Add(new Feature(line4));

                int featureCount = layer.InternalFeatures.Count;

                Vertex GORD = new Vertex(1, 1);
                Vertex newVertex = new Vertex(0, 0);

                for (int i = 0; i < featureCount; i++)
                {
                    LineShape tmpLine = layer.InternalFeatures[i].GetShape() as LineShape;
                    for (int j = 0; j < tmpLine.Vertices.Count; j++)
                    {
                        if (tmpLine.Vertices[j] == GORD)
                        {
                            tmpLine.Vertices[j] = newVertex;
                        }
                    }
                    layer.InternalFeatures[i] = new Feature(tmpLine);
                } 
 
  
 Regards, 
  
 Don

Thanks Don, very useful information, but I have figured out I can use CreateShapeFromWellKnownData for my new shape by calculating new points. Probably should have been a little clearer of what I was attempting to do.

 myfeature = New Feature(BaseShape.CreateShapeFromWellKnownData("LINESTRING(" + shapeXstart + " " + shapeYstart + "," + pointXend + " " + pointYend  ")"))



Thanks again

Hi Craig, 
  
 Yes your solution is better here, thanks for you sharing, I think that’s helpful for other guy who met same issue. 
  
 Regards, 
  
 Don