Creating a cost surface in Manifold

Recently I have played a bit with manifold to find out how to prepare a cost surface. There are no out of the box tools in manifold to magically create such a surface but a bit of sql does the job.

Lets assume we have two components - a surface and a drawing. Surface will be a container for our output data and the drawing will provide the input - in this case a bunch of simple lines imitating a road or stream network.

Lets start with preparing an output surface - simply copy the drawing and paste it as a surface and when done run an update query to set the cell values to 0:

UPDATE [Surface] SET [Height (I)] = 0

When our surface is ready we can start playing with generating a cost surface (in this case this will be a distance from the nearest vector object):

UPDATE
(SELECT
	[Surface].[Height (I)],
	Distance(
		AssignCoordsys(
			NewPoint([Center X (I)],[Center Y (I)]),
			CoordSys("Surface" AS COMPONENT)
		),
		Line.[Geom]
	) AS [Distance]
FROM
	[Surface],
	(SELECT AllBranches([Drawing].[Geom (I)]) As [Geom]
	FROM [Drawing]) AS Line)
SET [Height (I)] = [Distance];

 After running this query our surface should look like this:

So far s good but let's have a look at raster reclassification to make the output a bit more useful for further usage. We can write another query that will update our already generated surface, though for this example I have decided to combine it with the query above:

UPDATE
(SELECT
	[Surface].[Height (I)],
	Distance(
		AssignCoordsys(
			NewPoint([Center X (I)],[Center Y (I)]),
			CoordSys("Surface" AS COMPONENT)
		),
		Line.[Geom]
	) AS [Distance]
FROM
	[Surface],
	(SELECT AllBranches([Drawing].[Geom (I)]) As [Geom]
	FROM [Drawing]) AS Line)
SET [Height (I)] = 
	CASE
		WHEN  [Distance] < 5 THEN 0
		WHEN  [Distance] < 10 THEN 1
		WHEN  [Distance] < 15 THEN 2
		WHEN  [Distance] < 20 THEN 3
		WHEN  [Distance] < 25 THEN 4
		WHEN  [Distance] < 30 THEN 5
		WHEN  [Distance] < 35 THEN 6
		WHEN  [Distance] < 40 THEN 7
		WHEN  [Distance] < 45 THEN 8
		ELSE 9
	END

 So now our surface looks like this:

What's next? Having prepared more surfaces for analysis one can now combine them using surface tools. If surface tools are not avaialble it is easy enough to combine surfaces using the UPDATE technique shown above.

If you want to play a bit with the examples shown here just download this file: example.map (1.00 mb)

blog comments powered by Disqus