Subscribe to this thread
Home - General / All posts - Line midpoints (again)
orerockon

377 post(s)
#03-Sep-19 21:04

I had asked how to create midpoints on a line, and I got it to work. I don't have that file anymore and it's been a few years since I've used MFD (8.0.30.0). This worked, but I can't figure out how to do it now. Can someone explain in language that a rusty novice could follow?

Make centroids on line

Copy/Paste all objects in a Drawing linked to the following query into a Duplicate of the [Drawing]

containing the lines where beforehand you deleted all the line objects to have only the table stucture.

--SQL

SELECT LinePoint([ID],[Length (I)]/2) AS [Geom Center] FROM [Drawing]

Run the query, in the query results table link a drawing with type = geometry column and source = the query table (leave the other fields alone). The linked drawing now contains the midpoints of the lines in

the drawing. This linked drawing table only contains the ID column.

Copy and paste all the points into the (empty) duplicate of the original drawing containing the lines (none of the columns are populated).

Do a spatial overlay between the midpoints and the lines. The drawing linked to the query has to be reprojected to the same coordinate system and precision as the original drawing (and thus the duplicate with the midpoints) before a spatial overlay will work. Since the points didn't have any columns populated (except for the spatial overlay from the HUC drawing), delete all other columns in the duplicate drawing so only the one column was transferred.

I didn't try duplicating the linked drawing and doing a spatial overlay from that. The query did only create midpoints and didn't contain the attributes. You have to Spatial Overlay the original lines to these points and that is why you need the same table structure. You could as well fill in a query of this type

SELECT <list of columns in Drawing>, LinePoint(.... and relink. Now the midpoints have all the original attributes from the beginning.

oeaulong

213 post(s)
#03-Sep-19 23:28

I am confused. Are you using Mfd 8 or 9? Can you elaborate on what it is you are missing or trying to achieve? Using Mfd8, your query works but you are not bringing along any extra data columns. Is this what you are trying to accomplish? If so, add the columns of the [Drawing] table to the SQL query. Most of the post is a recipe for a workaround solution, so I am not really understanding what it is you are trying to remember.

As an aside, I found the use of LinePoint() unintuitive (rather than centroid), though seemed to work, especially on 'U' shaped multi-segment line. Added this little tidbit to my knowledge.

Dimitri


5,519 post(s)
#04-Sep-19 08:06

Make centroids on line

In 9, just use the Transform pane, Center template. That creates a centroid for each line. You can add a component and set the options to transfer fields however you like. Done! No need for any SQL or complicated workflow.

If you are curious what SQL is used to accomplish that, press the Edit Query button to see..

UPDATE (

  SELECT [mfd_id],

    [Geom],

    GeomMakePoint(GeomCenter([Geom], 0)) AS [n_Geom]

  FROM [Drawing]

  THREADS SystemCpuCount()

SET [Geom] = [n_Geom];

Easy. :-) The above is to just update the component to create centroids. If you want to add a new component that is centroids, set that up first by choosing Add Component in the action button and then press Edit Query to see the SQL for putting your results in the new query.

tjhb

8,846 post(s)
#04-Sep-19 13:16

Line centroids are not midpoints, except for the trivial case of lines with one segment (or by accident).

orerockon

377 post(s)
#04-Sep-19 18:54

Yes that's my issue exactly. I am trying to transfer fields from various geographic coverages to stream lines at various points. Obviously the endpoints are trivial but I'd like to use the midpoint as well. For example transfer elevation from the 10m DEMS. I found a sneaky way to do some of it last night, transfer heights and generate the max, min, and mean elev which is part of what I need. But obviously that doesn't give me the midpoints. Unless there's a way to transfer (heights or something else?) and figure out where the mean elev lies. The next thing I will try is to find that elevation on the lines but that's where I get stuck (without a lot of clicking). Clunky I know but might work, I only have 18 points to generate and need the elevations for all the watersheds anyway. Can you generate a point cloud from the DEMs? Then find the closest point that has the mean elev that was transferred to the segments? I tried to use the watersheds tool but that just generates nonsensical stream segments. Probably because they don't have any finer scale for my AOI.

Dimitri


5,519 post(s)
#04-Sep-19 20:07

Line centroids are not midpoints, except for the trivial case of lines with one segment (or by accident).

Very true. I was responding to "Make centroids on line"... Since a centroid is only on a line for straight lines (can have more than one segment, so long as they are all in the same direction), I assumed that was the case.

As for orerockon's request, there's a cheat that might be a useful approximation: create buffer areas around each line of interest, and then transfer the average height from the DEM within each buffer to the buffer, using the process given in this example topic.

If you want to find a location approximately midway through each line, you could find the Center, Inner of each buffer area. Depending on the shape of the original line, that might not be too far off from the approximate midway position. I'll think about a query to find and generate the actual midway position of an intricate line.

orerockon

377 post(s)
#05-Sep-19 02:51

I did transfer the heights to buffers. It does OK for straight segments, convoluted segments not so much. I need to mess with it some more. Ultimately accuracy isn't all that important since they are generally longer than 5 km and have gradients right around 1%. So it isn't going to change much if it's 100 m off. Think of all the fun I could have with a routine...so many streams...I'd do it just for fun :)

mikedufty

845 post(s)
#09-Sep-19 08:17

This just came up for me.

Someone wants to convert transects to a point at the middle to use as a GPS waypoint.

I tried to use oeaulong's suggestion and include data columns of the drawing in the query, but don't know how, or even how to find the right part of the help file.

With some trial and error I got this to work.

code

SELECT LinePoint([ID],[Length (I)]/2),[Name]  FROM [Line Drawing Source]

where Name is the column with the transect name.

I then had to create a linked drawing to convert the query to a point drawing.

Some questions -

This seems to work, but is it the best way to do it?

Is there a simple way to include all table columns in the point rather than manually adding to the query?

Can a query be set up to return a drawing, or is the linked drawing bit necessary?

tjhb

8,846 post(s)
#09-Sep-19 08:56

.

rk
331 post(s)
online
#09-Sep-19 09:11

* This is exactly the way to get line midpoint

* For an ad-hoc query, you can write [d].* to include all columns

--SQL

SELECT 

 [Line Drawing Source].*

   ,

 LinePoint([Geom (I)],[Length (I)]/2) as [MidPoint]

FROM

 [Line Drawing Source]

* Linked drawing is often very useful.

(So useful that I have remebered the sequence of keys to create one quickly -- Alt+F,L,D ; Home ; Enter ; Down Arrow ; Tab ; <first letters of wanted component name' ; Alt+G ; 'm - for [MidPoint]' ; Enter )

* But you can create a drawing beforehand by copying [Source], making it emtpy and use INSERT query.

Now you have to spell all names out (twice) -- tedious at first.

--SQL

INSERT INTO [Target] ([Name], ..., [Geom (I)])

(

SELECT 

 [Name]

   ,

   ...

   ,

 

 LinePoint([Geom (I)],[Length (I)]/2) as [Geom (I)]

FROM

 [Line Drawing Source]

)

mikedufty

845 post(s)
#09-Sep-19 09:31

Thanks,

Tried your version and discovered maybe I didn't really want all the columns, since it brings in geometries and intrinsics from the source lines.

Figured out I need to use midpoint as the geom for a linked drawing from that one.

I've saved both versions for future use.

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.