More

OpenLayers - Add points at vertices of line while drawing line

OpenLayers - Add points at vertices of line while drawing line


I would like to create points while I draw a line on my map in OpenLayers. That is, at each vertices of a line and at the end points there is a shape like a square, circle, or diamond.

I have this partially working. I can add points at the vertices of a line while I'm drawing it but they are one off. The point/shape doesn't render at the beginning of the line but at the second point in the line as you can see below. Also, the end of the line has two points/shapes; you can't see it since they are stacked.

Here is my code that adds the point/shape as I'm drawing my line (see thepointcallback in myDrawFeaturecontrol setup).

var path_control = new OpenLayers.Control.DrawFeature( vector_layer, OpenLayers.Handler.Path, { callbacks: { point: function( point ) { console.log(point); point_collection.push(point); var feature = new OpenLayers.Feature.Vector( point ); vector_layer.addFeatures([feature]); vector_layer.redraw(); } } } );

console.log(point)gets called at all the correct times. When I output mypoint_collectionvariable that I setup to figure out what is going on, the points are different than those output byconsole.log(point)from with thepointcallback.

I have a feeling that it has something to do with when I'm actually adding the points to the vector layer but can't figure it out.


Select the verts you want to align. If they are all on the same edge you can select the edge loop from the Select menu.

Scale on the axis you want to align them all to, and type "0".

Type in a location value for that axis. I find aligning to 0 first, and then positioning, to be sufficient for most cases.

However, there are times when you'll want to use the 3D cursor instead of aligning first and then positioning.

There are also cases where you may want to use a custom axis (transform orientation). The following method describes how to do that.


You can add fixed points by changing the style, as per this example.

The accepted answer links to the right documentation but it seems helpful to have a fully detailed answer on Stack Exchange, including a copy/pasteable example.

Pick "Edit Style" from the context menu

Add a key points with a value with an array of coordinates (values between 0 and 1 for place on the side of a shape), e.g. points=[ [0.0, 0.0], [0.0, 0.5], [0.0, 1.0], etc ]

Click apply and you're done.

Here's a particularly useful example:

10 anchor points per side (incl. corners):

Or, the full style for a default white rectangular box:

Also useful for standard boxes, example with 5 points on left/right, and 10 on top/bottom:

Hope this helps someone, I wrote a python script to generate the string for evenly spaced points on a rect


Working with vector KML

KML (Keyhole Markup Language) is a popular format for vector GIS features due to its association with Google Earth and Google Maps. KML is just XML formatted according to an open specification, previously maintained by Google, but now enshrined in an OGC standard. Although KML can define the placement of raster layers, we will focus on vector KML in this lesson.

The key XML tag behind KML is the placemark. This defines a geographic feature, a symbol, and extra information that can appear in a popup. You can see some placemarks if you save the example KML file and open it in a text editor. This isn't the cleanest file, but it will do for the purposes of seeing a placemark:

Notice how the strategy is defined as Fixed. This means that all the features in the KML file will be loaded into the browser at the time the map is loaded.

The KML is invoked using the OpenLayers.Protocol.HTTP object (as opposed to the OpenLayers.Protocol.SQL object which connects to databases). You have to specify the path to the file (which can be a full URL or a relative path like the one above) and then specify that the format is OpenLayers.Format.KML. If you look at all the OpenLayers.Format classes in the API reference table of contents (see sidebar on the left, click on "Format" to unfold the list), you will see many types of data you can add to your map as vectors.

Again, don't worry about memorizing all the syntax. In most scenarios, you should just be able to tweak the above example to connect to your own KML. The API reference and other online samples can help you further with understanding all the available properties.


7 Answers 7

You can use the regular polygon shape from the shapes.geometric library, setting draw=none . Giving the node the name a , the vertices will be named a.corner 1 , a.corner 2 etc.

Time to call foreach . Of course, it is possible to use a lot of other tools.

Here are some other possible options, if you want to change colors.

Here is a PSTricks solution (with some extra features -- just remove the code not needed or outcomment it):

Since someone added an asymptote tag, I'll go ahead and give an Asymptote solution. Note that the programming abilities of Asymptote have the following advantages:

  1. You can store all the points in an array, which makes it easy to reference them.
  2. It is easy and natural to create points for future reference without drawing them, if so desired.

The solution (with comments):

A recommended solution with PSTricks. Note that n -side polygon needs n+1 for the plotpoints .

curvepnodes (implemented in pst-node ) needs plotpoints (implemented in pst-plot ). It seems to be a bit weird as IMHO, pst-node implementing curvepnodes should load pst-plot internally to make plotpoints available.


OpenLayers - Add points at vertices of line while drawing line - Geographic Information Systems

Easy Installation: The install program adds the application so that it is automatically loaded with Civil3D. Control the application with your choice of command line entry, pulldown menu, or ribbon interface.

Extended Data
Draw: Draw geometry (hatches, mtext, inserts) based on values in extended data.
Edit: Edits the MapWorks extended entity data on a single object. Dockable palette automatically shows extended data when one object is selected.
Manager: Allows xdata management operations across a selection set of objects.
Image Process
Symbols: Go straight from your GPS enabled camera to CAD! Locates symbols representing GPS Photos (with EXIF data) directly from images. Creates a hyperlink to the image, projects to drawing system, rotates to view (if bearing data exists), and more.
Link Inspect: Shows linked images in a resizable preview window as you move the crosshair over objects (such as polyline house outlines) containing links.
TMS Images: Builds insert-able images from TMS (Tile Map Service) servers. Produce plan view maps, satellite imagery or terrain images.
GPS Update: Select inserts with hyperlinks and updates the GPS Exif (geotagging information) in source images. Adds GPS properties to images that never had geotag information.
Plot Rasters: Plots multiple layouts to rasters at specified resolution and creates companion world files.
Resolution: Change (lower) the resolution of a selection set of image while maintaining size and position.
World: Inserts multiple TIF/JPG/PNG/SID images based on world files or creates a World TFW/JGW/PGW/SDW file from a selected image (even rotated).
Other Tools

The import tool can do a coordinate projection during import. Simply assign source systems for each file (some auto-detected) and a target system. If you don't see your format listed, contact us. We are always looking to add additional formats to our list.


5. The processing toolbox

The Processing Toolbox allows you to perform a great variety of geospatial functions, we'll focus on a few that are particularly useful.

To open it, click on the Toolbox icon at the top toolbar.

This will open the Processing Toolbox panel.

The dissolve tool

The dissolve tool allows you to remove the boundaries between connected or overlapping shapes within a layer. This effectively converts multiple overlapping shapes into a single contiguous shape. Here is an example of overlapped shapes:

In the Processing Toolbox panel, type ' dissolve ' into the Search. box.

There are several related tools which have 'dissolve' in their name, double click the Dissolve function under Vector geometry (with the QGIS logo ), which will open the Dissolve window. Confirm the correct layer appears in the Input layer dropdown, then click Run

The Dissolve window will switch to the Log tab, which confirms that the process is complete. Once this appears, you can close the the Dissolve window.

There is now a new scratch layer called Dissolved .

And the newly dissolved shape appears on the map.

Buffer tool and examples

A buffer extends the boundary of a shape by a defined amount. It's not simply resizing the shape, but using the shape as a starting point and expanding it. Using the shapes made in the last few examples, I'll show how different kinds of buffers work.

To access the buffer tool, type ' buffer ' into the search bar of the Processing Toolbox panel:

Then double click the Buffer function under Vector geometry (with the QGIS logo ), which will open the Buffer window.

Degrees instead of metres!

If you see this warning message, you'll need to take some additional steps before using the buffer tool.

Coordinate reference systems are beyond the scope of this guide. Suffice to say when working on an area, it's a good idea to use a projection designed specifically for that area. My points layer is set to EPSG: 4283 which is used for the entire world. I'll instead reproject the layer to a more suitable projection.

To do this, right click your layer, then choose Export and Save Features As.

Click the icon next to CRS , which will open the Coordinate Reference System Selector window.

MGA zones are a good way to work on features in Australia. To find these type 283 in the Filter box of the Coordinate Reference System Selector . Click on one of the zones under Predefined Coordinate Reference Systems and the suitable area will display in red in the map view.

The area I'm using is in Melbourne, so I'll choose 28355 and click OK :

Next click the Browse icon next to File Name , and choose an appropriate name and file location to save in.

Once a name and location have been chosen, click OK , making sure Add saved file to map is ticked:

I now have an identical layer with the reprojected points:

And the warning about degrees doesn't show for this layer:

Buffering a point

With each of my points as the centre, I'd like to see the area covered by a circle with a 30km radius. To achieve this, in the Distance field, type 30 , and set the units dropdown from metres to kilometres . Then set Segments to 99 and click Run :

When the Buffer window switches to the Log tab, this indicates the process is complete. Once this appears you can close the Buffer window.

There is now a new scratch layer called Buffered .

And the newly buffered shapes now appear on the map.

Dissolve and buffer

Dissolving a buffer can be helpful when buffering multiple items simultaneously.

If I were to make a 40km buffer around these points, the resulting shapes now overlap:

The output from buffering can be dissolved in another step, but we can save time by selecting Dissolve result :

The resulting shape is now a single polygon:

Buffering a line

Using the line I drew over Perth to reflect a road, I'd like to see the area covered by a 300m buffer from the road. To achieve this, in the Distance field type 300 . By default this should be set to metres. If not, change the unit to metres. Lastly set Segments to 99 then click Run :

When the Buffer window switches to the Log tab, this indicates the process is complete. Once this appears you can close the Buffer window.

There is now a new scratch layer called Buffered :

And the newly buffered shape now appears on the map.

Buffering a polygon

Using the polygon I drew over Kangaroo Island, I'd like to see the area covered by a 200m buffer. To achieve this, in the Distance field type 200 . By default the units should be set to metres. If not, change the units. Lastly set Segments to 99 then click Run :

When the Buffer window switches to the Log tab, this indicates the process is complete. Once this appears you can close the Buffer window.

There is now a new scratch layer called Buffered :

And the newly buffered shape now appears on the map.

Segments? End caps? Join styles? Miter limits?

Most of these settings will be unnecessary, however it's useful to understand them, especially segments. The following are examples to demonstrate the effects of these settings.

Segments

In QGIS, segments refers to the number of lines used to draw a quarter of a circle. Below are several examples showing what a circle would look like drawn with progressively more line segments:

From left to right, these circles are drawn with 4 lines, 8 lines, 12 lines, 16 lines, and 20 lines.

QGIS asks for the number of line segments over a quarter of a circle. To understand this, we can look at a quarter of the above shapes with a conceptual perfect quarter circle overlaid.

From left to right, these quarter circles are drawn with 1 line, 2 lines, 3 lines, 4 lines, and 5 lines.

QGIS allows anywhere from 1-99 segments. For most cases 99 segments will be ideal.

End caps

End caps are the shape used by QGIS when buffering the end of a line. There are three options: round, flat and square.

A round end cap adds a rounded section to the end of the buffer. The same rules about segments (see previous section) apply to a round end cap. Here's an example:

A flat end cap finishes the buffer exactly at the end of the line, there is an example below:

A square end cap adds a square-shaped section to the end of the buffer, here's an example:

Join Styles

QGIS has three options to draw corners when buffering a polygon: round, miter and bevel.

A round join style follows the same rules about segments mentioned in the previous section. It adds a round corner, as shown below:

A miter join style adds additional space beyond the corner of the shape, and caps the end with a flat surface, as shown below:

The bevel join style takes the buffer drawn from each side of the shape, and adds a flat line on each corner to connect them, shown below:

Miter limit

This setting applies only when using the miter join style: it sets how long the miter will go beyond the corner of the shape.


2 Answers 2

According to this Wikipedia article, if the origin is at the centre, then you can take the vertices to be

The article does also give some alternatives such as $(1, 1, 1, ), (1, -1, -1), dots $ which might be easier to work with.

I happened to have a suitable image on my laptop (for my freshman course), so I couldn't resist

It is supposed to be a methane molecule as opposed to a tetrahedron, so think of the hydrogen atoms (green) as vertices of the tetrahedron. As you see, this is the second arrangement in Old John's (+1) answer. One vertex is at the point $(1,1,1)$ and the other three at the points $(pm1,pm1,pm1)$ with exactly two minus signs occuring. In other words, four selected corners of a cube.

I second Old John's opinion that this is very well suited for 3D-rotations, because you surely know the effect of a rotation on the cube.


Tests

There are three subject matter tests and one cumulative test that will be administered during class time. Tests are NOT open book or notes. Each subject matter test will consist of 20 questions - 10 questions covering the lecture material and 10 questions covering the exercises. The cumulative test will consist of 40 questions - 20 lecture questions and 20 exercise questions. Each question is worth 0.5 points. Tests are structured to measure and reinforce overall comprehension.


Vector Data Formats

The Vector Data Model is only a general strategy for representing objects there are dozens of physical data structures (file format) that organize vector geometry and attributes in different ways, with unique capabilities. For example, some formats are able to store topology while others cannot some formats store the geometry and attributes in separate files, while others (typically called spatial databases) store the geometry as one column in the attribute table.

Non-GIS graphical software, including CAD and drawing programs such as Adobe Illustrator, are also based on the vector model.


Watch the video: Openlayers 6 Tutorial #9 - Interaction With Vector Features