Subscribe to this thread
Home - General / All posts - M9 Script to save linked data sources
danb

2,067 post(s)
#15-Sep-23 01:46

I have an additional question relating to linked image files. I have now got write access to the folder location where the images are stored and so can write MAPCACHE sidecars for each image.

However, when I link the images and put them into a map (there are many thousands), Manifold writes an empty MAPCACHE file in the image source folder location but saves no data to it unless I save each datasource which now has an asterisk by it to show it has unsaved data.

To do this manually is totally impactable as there are several thousand files and as such I was wondering if someone has a script that they would be willing to share to do this?

Many thanks as always


Landsystems Ltd ... Know your land | www.landsystems.co.nz

danb

2,067 post(s)
#15-Sep-23 02:44

I have found a solution to this. If I save the map project once all of the images have been opened in a map (and hence their caches have been built), it will automatically save all the MAPCACHE files for the linked images with no scripting required


Landsystems Ltd ... Know your land | www.landsystems.co.nz

danb

2,067 post(s)
#15-Sep-23 02:50

On the off chance it is of use to others. Here is my naively written SQL to add thousands of linked images with a folder to a map:

-- Folder containing linked images

VALUE @FOLDER NVARCHAR = '1 SOURCE\\LINKED\';

-- --------------------------------------------------------------------------------------------------------------------------- 

VALUE @QRY1 NVARCHAR = '

CREATE MAP [MAP LINKED] (

  PROPERTY \'CoordSystem\' \'EPSG:2193,mfd:{ "Axes": "XY" }\',

  <QRY>

);

';

-- ---------------------------------------------------------------------------------------------------------------------------

-- Cleanup

DROP MAP [MAP LINKED];

DROP TABLE [TMP];

DROP QUERY [Q1];

SELECT '[' + [NAME] + ']::[' + [NAME] + ']' AS [SRC] 

INTO [TMP]

FROM [mfd_meta] WHERE [PROPERTY] = 'Folder' AND [VALUE] = @FOLDER;

ALTER TABLE [TMP] (

  ADD [mfd_id] INT64,

  ADD INDEX [mfd_id_x] BTREE ([mfd_id])

);

-- Build empty query component 

CREATE QUERY [Q1] (

  PROPERTY 'Text' '<TEMPLATE>'

);

-- Build Query

UPDATE [mfd_meta] SET [VALUE] = 

(

SELECT StringReverse(StringReplaceNth(StringReverse([STR]), ',''', 0)) AS [STR]

FROM

 (

 SELECT 

 StringReplace(@QRY1, '<QRY>',

 StringJoinTokens('PROPERTY \'Item.' + CAST([mfd_id] AS NVARCHAR) + '\' \'"Entity""' + [SRC] + '""Z"' + CAST([mfd_id] AS NVARCHAR) + ' }\',', CRLF)

 AS [STR]

 FROM [TMP]

 )

)

WHERE [NAME] = 'Q1' AND [PROPERTY] = 'Text';

-- Run the insert

EXECUTE [Q1];

-- Cleanup

DROP TABLE [TMP];

DROP QUERY [Q1];


Landsystems Ltd ... Know your land | www.landsystems.co.nz

tjhb
10,105 post(s)
#16-Sep-23 02:43

Very nice.

So you are using <QRY> as a one-time JIT replacement token? That looks clever.

Would it be nice if we could do the same to raise a prompt? Though I’m not sure adamw would like compiling anything on a delayed promise.

(From your query, it seems he allows that de facto already. Clever men.)

danb

2,067 post(s)
#16-Sep-23 08:05

Thanks Tim,

You are onto it. I use this general method for all sorts of SQL 'automation' as I am hopeless at scripting for M9. On some of my applications of this method, the EXECUTE fails to run, but I can always run the stack manually.

I wish that what i am trying to automate here was as easy to do this as it is for imported images and drawings.

I always thought it was particularly neat that you could simply import a bunch of drawings, images etc into a folder in M9, right click on the folder and select create map, to be offered a map dialogue with all of the folder contents in the map layer list already there.

Now if we could just do the same for linked data!


Landsystems Ltd ... Know your land | www.landsystems.co.nz

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