Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smooth grid edges #23

Open
rpachaly opened this issue Oct 27, 2023 · 19 comments
Open

Smooth grid edges #23

rpachaly opened this issue Oct 27, 2023 · 19 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rpachaly
Copy link
Collaborator

Find a way to smooth the grid edges like Mapper

image

image

@rpachaly
Copy link
Collaborator Author

@FLO-2DKaren
Hi Karen. Do you have any idea on how to do this on QGIS? I'm trying to find an efficient way to do the same thing that mapper does but nothing seems to smooth the edges the way mapper does.

I need to run a couple of algorithms to get the same mapper result. It will take around 3-5 seconds per map I think.

@FLO-2DKaren
Copy link
Collaborator

Did you use raster contour tool?

@rpachaly
Copy link
Collaborator Author

image

To get this kind of result, I follow these steps:

  1. Create the "Contour Polygons" from the raster
  2. Create the "Raster pixel to points"
  3. Create the "Concave hull (k-nearest neighbor)" using the "Raster pixel to points" -> to remove the square edges
  4. Apply the "Smooth" for better visualization using the "Concave hull (k-nearest neighbor)" -> it is not necessary
  5. Clip the "Contour Polygons" with "Smooth" to remove the edges.

It is not efficient but it works.

@rpachaly
Copy link
Collaborator Author

It works fine for continuous data, but for categorized data (e.g. hazard maps) it is bad.

@FLO-2DKaren
Copy link
Collaborator

Maybe we should see what the Mapper code is doing. I’ll ask JJ to give us some help.

@FLO-2DKaren
Copy link
Collaborator

@FLO-2DJJ hi JJ. Can you tell us how Mapper builds contour maps? If you follow this conversion you’ll get an idea of what’s happening with the raster maps.

@rpachaly
Copy link
Collaborator Author

hould see what the Mapper code is doing. I’ll ask JJ to give us some help.

Great idea! If I have to code everything, I'll have something to be based on.

@FLO-2DJJ
Copy link

FLO-2DJJ commented Oct 27, 2023 via email

@FLO-2DJJ
Copy link

1. Create the "Contour Polygons" from the raster
2. Create the "Raster pixel to points"
3. Create the "Concave hull (k-nearest neighbor)" using the "Raster pixel to points" -> to remove the square edges
4. Apply the "Smooth" for better visualization using the "Concave hull (k-nearest neighbor)" -> it is not necessary
5. Clip the "Contour Polygons" with "Smooth" to remove the edges.

@rpachaly hi Robson, can I see the code you are using here. Do you have a branch with this code so that I can see it? I t doesn't seem to be in the "new_mapping" branch.

@rpachaly
Copy link
Collaborator Author

@FLO-2DJJ
Hi JJ,

No, this is not coded yet. This is just the QGIS native algorithms that I intent to use. If you think this is a good approach, I'll code this way. Otherwise, feel free to suggest other approaches.

@FLO-2DJJ
Copy link

FLO-2DJJ commented Oct 28, 2023 via email

@FLO-2DJJ
Copy link

To create filled contours (shaded contours) in the old Mapper, like this Maximum Water Surface Elevation
image

it doesn't create contour lines first. Instead it creates a 2D rectangular matrix (280 x 222 in this example) with the value of the variable in each cell (or a very small negative value to indicate novalue). Then it calls a SimplePlot function (SimplePlot was the name software used) to create the the plot.
Maybe we could try a similar approach in QGIS. I have not found it yet.

@rpachaly
Copy link
Collaborator Author

Thanks JJ! This is a good direction to follow. I don't think that creating the contours is a good approach, specially for categorized data.

@rpachaly rpachaly added enhancement New feature or request help wanted Extra attention is needed labels Oct 30, 2023
@rpachaly
Copy link
Collaborator Author

The GRASS r.resamp.inter algorithm interpolate the raster values and create a very good internal result. But the edges are still grid-like and it misses some areas close to the raster's edges.

image

@rpachaly
Copy link
Collaborator Author

This plugin is also good. It creates contour polygons from points. https://github.com/ccrook/QGIS-Contour-Plugin

@FLO-2DJJ
Copy link

FLO-2DJJ commented Nov 1, 2023 via email

@FLO-2DJJ
Copy link

FLO-2DJJ commented Nov 1, 2023

Yes Robson, the https://github.com/ccrook/QGIS-Contour-Plugin plugin produces acceptable results. Let's try its several options to see if we can adopt it.

  • This is what I got when using the GROUND_ELEVATION raster layer:

imagen

  • From the GROUND_ELEVATION create a Vector points layer using Processing Toolbox. Vector Creation. Raster pixels to points:

imagen

It creates a 'Vector points' layer.

  • Symbolize it:

imagen
imagen

  • Use the aforementioned plugin with its defaults when you select the 'Vectors points' layer:

imagen
imagen

  • I suppose something has to be done to the initial raster or points layer to eliminate the cells (or points) with no value to obtain something similar to the old Mapper:

279021435-5e7f41d7-cc66-48ca-bab7-2deb931b2735

@rpachaly
Copy link
Collaborator Author

rpachaly commented Nov 1, 2023

That looks good! I'm think that the best option so far is to understand the Contour Plugin logic and adapt it to MapCrafter. I was worried about the processing time to create a map, but Mapper also takes some seconds to generate a Shaded Contour map.

@FLO-2DKaren
Copy link
Collaborator

I suggest we let the end users figure this out for now. Not many people request contours and those who do should be able to figure it out with the QGIS toolbox. Let's not spend more time on this. We have more important tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants