Subscribe to this thread
Home - General / All posts - M9 GeomClip
ColinD


1,872 post(s)
online
#26-Apr-18 08:09

I've been following the steps in help Clip Areas with a Transform Dialog Expression and am lost on syntax for when there is a clip area already available (in this case a rectangle) in the project. This is what I have so far:

PRAGMA ('progress.percentnext' = '100');

UPDATE (

  SELECT [mfd_id],

    [Geom],

    GeomClip([Geom], ([ClipArea], True, 0) AS [n_Geom]

  FROM [Drawing]

  THREADS SystemCpuCount()

SET [Geom] = [n_Geom];

Invalid object reference.


Aussie Nature Shots

tjhb

8,167 post(s)
#26-Apr-18 08:25

So [ClipArea] is a separate drawing (or table)?

In that case you will need a join, splicing the two sources together (and forming a virtual table inside the query).

For each row in the source table/drawing, there must be a clipping area in the same row. (It is a beauty of SQL joins that the clipping area can be either the same for each source object, or adaptive and different.)

Then you can perform one clipping operation per row.

ColinD


1,872 post(s)
online
#26-Apr-18 09:15

Tim, if that's the case why is it that the help examples using GeomMakeRect do not use a join?

rk maybe not, there are two pairs of brackets.


Aussie Nature Shots

tjhb

8,167 post(s)
#26-Apr-18 09:27

You are not using GeomMakeRect.

What is crucial is what and where [ClipArea] is.

If it is a column also in [Drawing] then Riivo's correct observation handles it.

Otherwise you need a join.

rk
271 post(s)
#26-Apr-18 09:28

then one ) is missing. you have 4 )-s and 5 (-s

If you want to clip one drawing A with all areas from other drawing B you can combine B to one area with function. (in my example A and B are in same table)

--SQL9

function aoi_holes() GEOM

AS

(

   SELECT  GeomUnionAreas([AreaGeom]as [AreaGeom] from [AOI] WHERE [IsHole]

)

END

;

UPDATE 

(

SELECT 

 [AOI].[mfd_id]

 ,

 GeomClip([AOI].[AreaGeom], aoi_holes(), false, 0) as [n_AreaGeom]

 ,

 [AOI].[AreaGeom]

FROM 

 [AOI]

WHERE

 NOT [IsHole]

 AND aoi_holes() IS NOT NULL

 

)

   SET [AreaGeom] = [n_AreaGeom]

;

ddd

tjhb

8,167 post(s)
#26-Apr-18 09:34

I think we should go back to Colin's original post. He puts his puzzle clearly.

I wish I could explain equally clearly!

I think example data, however trivial, is needed to do that. (Colin can you provide any?)

ColinD


1,872 post(s)
online
#26-Apr-18 10:46

Here's an example. The aim is to clip Bot_divs_LatLon with NSW_rect in the M8 manner of Clip With Intersect.

Thanks

Attachments:
Map.mml


Aussie Nature Shots

rk
271 post(s)
#26-Apr-18 11:20

Like this?

Note that Bot_divs outside are not deleted but [Geom] are set to NULL.

Attachments:
clip_area.PNG
m9_ClipArea.mxb

ColinD


1,872 post(s)
online
#26-Apr-18 12:06

Thanks but that hasn't quite worked Rivo. The partial areas at the edges of the clip are named unknown instead of the relevant Division name.


Aussie Nature Shots

adamw

8,037 post(s)
#26-Apr-18 16:03

But they have DIVISION set to 'unknown' in the original data, no?

Overall, two small notes:

I think Riivo's query is correct. I'd get rid of the WHERE check for the clip area not being NULL and do this manually, but that's minor. There are ways to improve performance for the general case - first do UnionAreas into a different table, and then just do First on that table instead of UnionAreas, because there's nothing to union. But that's for the general case, in this case the rect drawing is already just one record.

We are going to re-add the clip transforms to the Transform pane. We are missing a bit of the syntax currently (we want queries like this to be a little smarter than they can be so now, basically), this will be corrected.

Attachments:
unknown.png

ColinD


1,872 post(s)
online
#26-Apr-18 23:08

Ha! I didn't know my own data. The unknowns are indeed in the original. Odd. Thanks again for this.


Aussie Nature Shots

steveFitz

208 post(s)
#26-Apr-18 13:19

l tried to import Colin's mml file into the latest Viewer 9.0.166.5:

• file menu - nothing

• right click > Create data source - system data tables only

. . . and all on a windows tablet with a digitizer pen!

Even managed to freeze pen input pad writing this

(I'm not usually such a masochist)

adamw

8,037 post(s)
#26-Apr-18 15:48

(I cannot reproduce this. Launched Viewer 9.0.166.5, the 64-bit EXE. Invoked File - Import. Selected MAP.MML. It imported and created a map, two drawings and two tables.)

steveFitz

208 post(s)
#27-Apr-18 07:49

Apologies for hijacking Colin's thread - I should have started a new post.

I confim that mml doesn't load drawings (using methods Adam describes above) on 64 bit Win 10 tablet but does work on 64 bit Win 7 laptop. Even tried unblocking it to no avail.

adamw

8,037 post(s)
#27-Apr-18 09:30

I suspect this affects more than just MML.

Can you read KML or, say, GPX? There is a chance you cannot and if so, that's likely related to .NET on the tablet not being a full version.

steveFitz

208 post(s)
#27-Apr-18 23:10

No, can't read kml either. GPX seems to have drawings and tables but I can't see anything in them (poss my lack of knowledge on working with GPX).

Given SSD on tablet is only 128GB is it best not to have full .Net?

adamw

8,037 post(s)
#28-Apr-18 10:46

Full .NET is not that big so if you work with any of the XML-based formats, you should be able to install it just fine. But regardless, it looks like it might make sense for us to reduce dependencies on .NET.

Thanks for the test!

rk
271 post(s)
#26-Apr-18 09:00

You have one extra (

([ClipArea]

ColinD


1,872 post(s)
online
#26-Apr-18 23:54

Supplementary questions:

1. In Rivo's query, where does the function cliparea () come from? I don't see that in the functions list.

2. Can the query be adapted to clip a drawing of lines? Or a drawing containing both lines and areas?

Thanks


Aussie Nature Shots

tjhb

8,167 post(s)
#27-Apr-18 00:35

1.

He wrote it!

See

FUNCTION ClipArea() GEOM AS

...

END;

in Riivo's code.

In 9 we can write custom functions in SQL, C#, IronPython, VB.NET, vbscript, JavaScript ... basically anything.

Riivo has used a custom function rather than a join in response to your question about GeomMakeRect (a built-in function).

Using a custom function rather than a join might be significantly faster in this case. It would be interesting to see a comparison.

2.

Yes.

The query can be simplified a bit, as Adam says, but it should work as it is for points, lines or areas, or any combination of object types.

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