Help for script to draw a rectangle (DEFINE_SHAPE) based on coordinates, using variables
BillB
Global Mapper UserTrusted User
Hi folks
I have been tussling with this for an hour or so. It all works fine apart from the last section DEFINE_SHAPE which is intended to draw a rectangle based on the previously entered coordinates and page widths. I have tried DEFINE_SHAPE with and without the %% around the variables, but the script just appears to stop and do nothing at this point. Any suggestions?
//GlobalMapperScript for rect based on coordinate
GLOBAL_MAPPER_SCRIPT VERSION=1.00
// get centre coordinate (x,y), and height/width of rect to be drawn (m)
// var coordinate
DEFINE_VAR NAME="CEN_COORD_EAST" PROMPT="YES" PROMPT_TEXT="Enter site centre easting - six figures"
DEFINE_VAR NAME="CEN_COORD_NORTH" PROMPT="YES" PROMPT_TEXT="Enter site centre northing - six figures"
// var width
DEFINE_VAR NAME="PAGE_WIDTH" PROMPT="YES" PROMPT_TEXT="Enter the page width in metres (e.g. 8000)"
// Var height
DEFINE_VAR NAME="PAGE_HEIGHT" PROMPT="YES" PROMPT_TEXT="Enter the page width in metres (e.g. 6000)"
// create new NSWE extents
// North
DEFINE_VAR NAME="_NORTH" FORMULA="CEN_COORD_NORTH + (PAGE_HEIGHT/2)"
// South
DEFINE_VAR NAME="_SOUTH" FORMULA="CEN_COORD_NORTH - (PAGE_HEIGHT/2)"
// West
DEFINE_VAR NAME="_WEST" FORMULA="CEN_COORD_EAST - (PAGE_WIDTH/2)"
// East
DEFINE_VAR NAME="_EAST" FORMULA="CEN_COORD_EAST + (PAGE_WIDTH/2)"
// Confirm coordinates in dialog (temp info, not required in final version)
DEFINE_VAR NAME="DUMMY" PROMPT="OK" PROMPT_TEXT="The corner coordinates are: %_WEST%,%_NORTH% %_EAST%,%_NORTH% %_EAST%,%_SOUTH% %_WEST%,%_SOUTH% %_WEST%,%_NORTH%"
//draw rectangle using X,Y extents
DEFINE_SHAPE SHAPE_NAME="CROP_BOUNDARY_TEST"
%_WEST%,%_NORTH%
%_EAST%,%_NORTH%
%_EAST%,%_SOUTH%
%_WEST%,%_SOUTH%
%_WEST%,%_NORTH%
END_DEFINE_SHAPE
GLOBAL_MAPPER_SCRIPT VERSION=1.00
// get centre coordinate (x,y), and height/width of rect to be drawn (m)
// var coordinate
DEFINE_VAR NAME="CEN_COORD_EAST" PROMPT="YES" PROMPT_TEXT="Enter site centre easting - six figures"
DEFINE_VAR NAME="CEN_COORD_NORTH" PROMPT="YES" PROMPT_TEXT="Enter site centre northing - six figures"
// var width
DEFINE_VAR NAME="PAGE_WIDTH" PROMPT="YES" PROMPT_TEXT="Enter the page width in metres (e.g. 8000)"
// Var height
DEFINE_VAR NAME="PAGE_HEIGHT" PROMPT="YES" PROMPT_TEXT="Enter the page width in metres (e.g. 6000)"
// create new NSWE extents
// North
DEFINE_VAR NAME="_NORTH" FORMULA="CEN_COORD_NORTH + (PAGE_HEIGHT/2)"
// South
DEFINE_VAR NAME="_SOUTH" FORMULA="CEN_COORD_NORTH - (PAGE_HEIGHT/2)"
// West
DEFINE_VAR NAME="_WEST" FORMULA="CEN_COORD_EAST - (PAGE_WIDTH/2)"
// East
DEFINE_VAR NAME="_EAST" FORMULA="CEN_COORD_EAST + (PAGE_WIDTH/2)"
// Confirm coordinates in dialog (temp info, not required in final version)
DEFINE_VAR NAME="DUMMY" PROMPT="OK" PROMPT_TEXT="The corner coordinates are: %_WEST%,%_NORTH% %_EAST%,%_NORTH% %_EAST%,%_SOUTH% %_WEST%,%_SOUTH% %_WEST%,%_NORTH%"
//draw rectangle using X,Y extents
DEFINE_SHAPE SHAPE_NAME="CROP_BOUNDARY_TEST"
%_WEST%,%_NORTH%
%_EAST%,%_NORTH%
%_EAST%,%_SOUTH%
%_WEST%,%_SOUTH%
%_WEST%,%_NORTH%
END_DEFINE_SHAPE
Tagged:
Answers
-
Hello,
The DEFINE_SHAPE command does not handle variables correctly. I have opened bug #24919 to resolve this issue. We will post a message on this thread when the problem has been resolved.
Cheers,
Bob -
Bob, thanks for letting me know. Hope it doesn't take too long, as the script was meant to be a work-around for a feature which has been requested since 2013.If the DEFINE_SHAPE command had handled variables correctly, would the script have been correct?
-
Hello,
The changes to DEFINE_SHAPE have been implemented in Global Mapper 19 (latest daily build) and will be in Global Mapper 20.
That said, the DEFINE_SHAPE does not create a displayable feature. To do that, you should use DEFINE_TEXT_FILE to create an inline text file, then IMPORT it. Note that DEFINE_TEXT_FILE had the same limitations vis-a-vis variables, and was fixed at the same time as DEFINE_SHAPE.
Cheers,
Bob -
OK, thanks for letting me know, Bob. I'll take a look when I get chance and share the results if successful.
-
How does one call the attention of this forum's admin to spammers?
-
Just done it via email to GM Support - don't think there is away to report via the Forum
-
Thanks Bill. There really needs to be a way - like on many forum platforms - to flag such abuses.
-
Agreed! "Report as Spam" button needed. Looks like there should be a way with this forum software:
-
Yes, and to semi-quote @ellinasmith:"the process is not so tough but if you haven't proper ideas you must take the proper guidance. I am suggesting the Global Mapper forum admin visit
https://docs.vanillaforums.com/help/roles-permissions/#reactions
, you will definitely get your solution there."
-
p.s. - the naughty post has gone...
-
kbellis said:How does one call the attention of this forum's admin to spammers?
Thanks for being involved!
-
@samknight- No such behavior is visible on my Firefox browser.
-
And this is likely tied to Roles & Permissions, if I had to guess:
-
I don't see that toolbar either - is this a setting I can change, or is it set by forum admins?
-
The behavior is working now! Thank you admin
-
Ahh, great, can see the full toolbar now. Look out, spammers!
-
kbellis said:The behavior is working now! Thank you admin
Best,
Sam
EDIT: Moving my own reply down to it's appropriate place in the list, for some reason it inserted as a reply to the initial question.
-
That happened when I said it had answered the question! It moved to right under the initial question, not the second question
-
BillB said:That happened when I said it had answered the question! It moved to right under the initial question, not the second question
-
OK, back on topic, I have made some progress with the script. It neatly generates a five-point rectangle from the requested inputs - but as a line rather than as an area. The import_ascii needs to generate an area object so that, after being reviewed, it can then be exported as a Shapefile to define the area of a data purchase.Can anyone assist?//GlobalMapperScript for rect based on coordinate
// Start
GLOBAL_MAPPER_SCRIPT VERSION=1.00
// get centre coordinate (x,y), and height/width of rect to be drawn (m)
// var coordinate
DEFINE_VAR NAME="CEN_COORD_EAST" PROMPT="YES" PROMPT_TEXT="Enter site centre easting - six figures"
DEFINE_VAR NAME="CEN_COORD_NORTH" PROMPT="YES" PROMPT_TEXT="Enter site centre northing - six figures"
// var width
DEFINE_VAR NAME="PAGE_WIDTH" PROMPT="YES" PROMPT_TEXT="Enter the page width in metres (e.g. 8000)"
// Var height
DEFINE_VAR NAME="PAGE_HEIGHT" PROMPT="YES" PROMPT_TEXT="Enter the page height in metres (e.g. 6000)"
/ create new NSWE extents
// North
DEFINE_VAR NAME="_NORTH" FORMULA="CEN_COORD_NORTH + (PAGE_HEIGHT/2)"
// South
DEFINE_VAR NAME="_SOUTH" FORMULA="CEN_COORD_NORTH - (PAGE_HEIGHT/2)"
// West
DEFINE_VAR NAME="_WEST" FORMULA="CEN_COORD_EAST - (PAGE_WIDTH/2)"
// East
DEFINE_VAR NAME="_EAST" FORMULA="CEN_COORD_EAST + (PAGE_WIDTH/2)"
// Confirm coordinates in dialog (temp info, not required in final version)
DEFINE_VAR NAME="DUMMY" PROMPT="OK" PROMPT_TEXT="The corner coordinates are: %_WEST%,%_NORTH% %_EAST%,%_NORTH% %_EAST%,%_SOUTH% %_WEST%,%_SOUTH% %_WEST%,%_NORTH%"
//draw rectangle using X,Y extents
DEFINE_TEXT_FILE FILENAME="CROP_BOUNDARY_TEST-%PAGE_WIDTH%x%PAGE_HEIGHT%"
%_WEST%,%_NORTH%
%_EAST%,%_NORTH%
%_EAST%,%_SOUTH%
%_WEST%,%_SOUTH%
%_WEST%,%_NORTH%
END_DEFINE_TEXT_FILE
IMPORT_ASCII FILENAME="CROP_BOUNDARY_TEST-%PAGE_WIDTH%x%PAGE_HEIGHT%"
TYPE=AREA_ONLY
-
Hello,
Try adding CLOSED=YES to your feature definition, as shown below:DEFINE_TEXT_FILE FILENAME="CROP_BOUNDARY_TEST-%PAGE_WIDTH%x%PAGE_HEIGHT%"
Note that if you had multiple features, you would need to include CLOSED=YES on each of your area features. For more information about the recognized field names, look in the Global Mapper help file, in the Contents under Loading Data | Loading Generic ASCII Text | Special Attributes.
CLOSED=YES
%_WEST%,%_NORTH%
%_EAST%,%_NORTH%
%_EAST%,%_SOUTH%
%_WEST%,%_SOUTH%
%_WEST%,%_NORTH%
END_DEFINE_TEXT_FILE
Cheers,
Bob -
Thank you Bob, that solved it. The rectangle now imports as an area. Have added Shapefile export of the resulting area but struggling to get it to work at present. Will report back when complete.
Categories
- 12.7K All Categories
- 5.6K Features Discussion
- 342 Downloading Imagery
- 1.3K Elevation Data
- 380 Georeferencing Imagery Discussion
- 628 GM Script Language
- 53 User Scripts
- 113 GPS Features
- 414 Projection Questions
- 819 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 177 Announcement and News
- 908 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 562 Other Discussion
- 129 GIS Data Sources
- 27 Global Mapper Showcase
- 233 How I use Global Mapper
- 107 Global Mapper Forum Website