Global Mapper v25.0

Help for script to draw a rectangle (DEFINE_SHAPE) based on coordinates, using variables

BillB
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



Answers

  • bmg_bob
    bmg_bob Global Mapper Programmer
    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
  • BillB
    BillB Global Mapper User Trusted User
    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?

  • bmg_bob
    bmg_bob Global Mapper Programmer
    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
  • BillB
    BillB Global Mapper User Trusted User
    OK, thanks for letting me know, Bob.  I'll take a look when I get chance and share the results if successful.
  • kbellis
    kbellis Global Mapper User Trusted User
    How does one call the attention of this forum's admin to spammers?
  • BillB
    BillB Global Mapper User Trusted User
    Just done it via email to GM Support - don't think there is away to report via the Forum
  • kbellis
    kbellis Global Mapper User Trusted User
    Thanks Bill. There really needs to be a way - like on many forum platforms - to flag such abuses.
  • BillB
    BillB Global Mapper User Trusted User
    edited September 2018
    Agreed! "Report as Spam" button needed.  Looks like there should be a way with this forum software:

  • kbellis
    kbellis Global Mapper User Trusted User
    edited September 2018
    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."


  • BillB
    BillB Global Mapper User Trusted User
    :D

    p.s. - the naughty post has gone...
  • kbellis said:
    How does one call the attention of this forum's admin to spammers?
    If you hover your mouse over a message you should see a toolbar light up at the bottom of the message with various options, a spam report is one of those.  That flags it for review and lets us delete and ban the spam bot account. 
    Thanks for being involved! 
  • kbellis
    kbellis Global Mapper User Trusted User
    @samknight- No such behavior is visible on my Firefox browser.
  • kbellis
    kbellis Global Mapper User Trusted User
    And this is likely tied to Roles & Permissions, if I had to guess:

  • BillB
    BillB Global Mapper User Trusted User
    I don't see that toolbar either - is this a setting I can change, or is it set by forum admins?
  • kbellis
    kbellis Global Mapper User Trusted User
    The behavior is working now! Thank you admin :)
  • kbellis
    kbellis Global Mapper User Trusted User
    samknight said:
    OK great, took some fiddling around with settings for Trusted Users, there was a setting that must have gotten out of whack at the last update.

    Best,
    Sam
    I've never seen those added feedback flags before; only the option to "Quote
  • BillB
    BillB Global Mapper User Trusted User
    edited September 2018
    Ahh, great, can see the full toolbar now. Look out, spammers!
  • kbellis said:
    The behavior is working now! Thank you admin :)
    OK great, took some fiddling around with settings for Trusted Users, there was a setting that must have gotten out of whack at the last update.

    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. 
  • BillB
    BillB Global Mapper User Trusted User
    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 :)
    Ah, that makes sense, I've either not enough coffee after release day or too much, hard to say really.   ;)
  • kbellis
    kbellis Global Mapper User Trusted User
    BillB said:
    That happened when I said it had answered the question!  It moved to right under the initial question, not the second question :)
    This is the normal behavior, which is unfortunate as it seriously interrupts the thread's flow as well as making it possible for seemingly contradicting answers when taken out of temporal context.
  • BillB
    BillB Global Mapper User Trusted User
    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
       

  • bmg_bob
    bmg_bob Global Mapper Programmer
    Hello,

    Try adding CLOSED=YES to your feature definition, as shown below:
    DEFINE_TEXT_FILE FILENAME="CROP_BOUNDARY_TEST-%PAGE_WIDTH%x%PAGE_HEIGHT%"
    CLOSED=YES
    %_WEST%,%_NORTH%
    %_EAST%,%_NORTH%
    %_EAST%,%_SOUTH%
    %_WEST%,%_SOUTH%
    %_WEST%,%_NORTH%
    END_DEFINE_TEXT_FILE
    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.

    Cheers,
    Bob
  • BillB
    BillB Global Mapper User Trusted User
    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.