Results 1 to 4 of 4

Thread: Moving a polygon

  1. #1

    Unhappy Moving a polygon

    I was wondering if it was possible to move a whole polygon.

    I know this isn’t an option within GE, at least not yet. However I thought there might be some way of exporting a polygon to a spreadsheet and then making the adjustment there. Or maybe there is some way of editing the KML file directly (so I don’t need GE+).

    At the moment I have a small number of outlines I’d like to move but they each have over a thousand vertices so re-doing them isn’t really an option. The good news is their latitude isn’t changing, which should simplify things.

    Edit: I should add that these aren't external 3D objects, they're created with the GE polygon tool.
    Last edited by Hungry Donner; 08-19-2007 at 05:53 AM. Reason: clarification

  2. #2

    Default

    1. Save your polygon as a kml file

    2. open it in notepad, you'll find a list of coordinates near the bottom

    each vertex is listed like this: -62.13551501802419,21.66556410660197,0 (longitude, latitude, altitude)

    3. bring these into a spreadsheet, you want the longitude and latitude to have their own columns (this might take a bit of formatting)

    4. adjust the latitude by whatever value you want

    5. put these back into the file, being careful to preserve the formatting

    6. save and load into Google Earth



    So it is very possible, but tedious if you have much to change. To get things to go into my spreadsheet smoothly I had to make a bunch of adjustments (like putting each vertex on its own line) and then add all of the formatting back when I was done. However I think it would be relatively simple to make a program that did this. I don’t have the ability myself but I’m a moderator on a large gaming forum so hopefully someone over there can help me. If not my father is a programmer and I know this would be a snap for him.

    You could also adjust the longitude with this, but it would change the distances between the vertexes.

  3. #3

    Thumbs up

    I guess the ability to edit a post eventually expires . . . three posts in a row, I feel like such a spammer. Well someone was able to make what I needed and since this issue seems to come up a lot I figured I'd slip a link into this thread.

    The discussion that led to all of this can be found here and the program itself is here.

    It's quite simple and it does a very good job. There is a little prep work necissary but it's quick and easy to do.

    Step 1. Save your polygon as a KML file (not a KMZ!)

    Step 2. Open te KML and remove everything (including line breaks) before <coordinates> and after </coordinates>

    Step 3. Run the program. Adusting the X value changes the latitude, adjusting the Y value changes the longitude, and the number you enter is in terms of degrees

    Step 4. Replace all of the removed code


    Now you're ready to bring it back into Google Earth.


    Note: If you had taken a snap shot of the polygon this information won't be moved.

    Note: you may need to change your KML file into a TXT file to edit it.



    I can't thank Timeslip enough for this and I hope other people enjoy it as well. I also hope GE will one day get this feature, the warping that affects polygons is no different than the problems image overlays experience.

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    1

    Default Use perl to move a polygon

    Here is a perl script that will translate all the lat/log co-ordinates for you. Simply change the input file name and tell it the x and y offsets (in metres).
    co-ordinates must be in the line after "<coordinates>" e.g.
    <coordinates>
    174.945683238123,-37.0730601666305,0 174.947408641346,-37.0722661837206,0 174.947734854518,-37.0726993508168,0
    </coordinates>

    Everything else is just echoed to the screen


    #!/usr/bin/perl

    ## ENTER X and Y move distances
    # y = metres of latitude to move polygon
    $y=199;
    # x = metres of Longitude to move polygon
    $x=25;

    $inputfile="mypolygons.kml";
    my $pi = 4*atan2(1,1);

    ## END OF VARIABLES
    open(INPUT,$inputfile) || die ("Can't open input file $inputfile");

    ## REPEAT FOR EACH LINE OF INPUT FILE
    while($line=<INPUT>) {
    if ($line =~ /\<\/coordinates\>/) {
    $found=0;
    };
    if ($found==1) {
    $line =~ s/^\s+//;
    chomp($line);
    @coord_array = split(/ /,$line);

    print "\t\t\t\t\t\t\t";
    foreach $coord (@coord_array) {
    ($long,$lat,$z) = split (/\,/,$coord);
    # 1852 metres per nautical mile (nm)
    # 1 Nautical mile (nm) = 1 second of longitude at the equator
    # i.e 60nm per degree of longitude at the equator
    $newlat = $lat+($y/1852)/60;
    $newlong= $long+($x/1852/60 * cos($lat/180 * $pi)); # 180 degrees = Pi radians
    print "$newlong,$newlat,0 ";
    } # end foreach
    print "\n";

    } else{
    print "$line";
    };# end else

    if ($line =~ /\<coordinates\>/) {
    $found=1;
    };
    };#end while

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •