Message Boards Message Boards


What's wrong with my code? Code and error are in the message.

Posted 8 years ago
4 Replies
0 Total Likes

What's wrong with my code?

My code is as follows:

(* Create empty lists *) xlist={}; ylist={}; zlist={}; latlonlist={};

(* Take inputs for ECEF *) (Label[startinput];x = Input["What is the x coordinate?"]; y = Input["What is the y coordinate?"]; z = Input["What is the z coordinate?"]; AppendTo [xlist, x] AppendTo [ylist, y] AppendTo [zlist, z] (Label[errorcontrol]; again=InputString["Enter more coords? Y for yes, N for no"]; If [again=="Y", Print["Okay!"];Goto[startinput]]; If [again!="N", Print["Sorry, this is an invalid input here!"];Goto[errorcontrol]]; If [again=="N", Print["Okay."]]));

(* Debugging *) (* Print[xlist] Print[ylist] Print[zlist] Print[x] Print[y] Print[z] *)

(* Combine Lists *) list=Transpose[{xlist,ylist,zlist}]

(* More Debugging *) (* Print[list] *)

(* Find length of list *) qty=Length[list] Print[qty]

For[i = 1, i < qty, i++, point = Part[list, i]; GeoPositionXYZ[point, "ITRF00"]; latlonlist = AppendTo[latlonlist, GeoMarker[GeoPosition[%]]]; ];

(* (* Put in Coordinate Form *) GeoPositionXYZ[{x, y, z}, "ITRF00"];

(* Convert to LLA *) GeoPosition[%] *)

(* Display Map *) GeoGraphics[latlonlist, 7GeoRange -> "World", GeoProjection -> "Robinson"]

(* Display 3D Plot *) ListPointPlot3D[list, DataRange -> {{-1000000, 1000000}, {-1000000, 1000000}}]

However, GeoGraphics returns:

GeoGraphics[{GeoMarker[GeoPosition[Null]], GeoMarker[GeoPosition[Null]]}, 7 GeoRange -> "World", GeoProjection -> "Robinson"]


POSTED BY: Nathan Lundholm
4 Replies
Posted 8 years ago

Took a little different approach:

    {intype, in = {0, 0, 0}, xyzCoords = {}, latlongCoords, again = True, outtype},
    intype = ChoiceDialog["Type of input?", {"x,y,z" -> 1, "All" -> 2}];
            in[[1]] = Input["What is the x coordinate?"];
            in[[2]] = Input["What is the y coordinate?"];
            in[[3]] = Input["What is the z coordinate?"];
            AppendTo[xyzCoords, in];
            again = ChoiceDialog["Enter more coords?", {"Yes" -> True, "No" -> False}]
     2, xyzCoords = Input[]
    latlongCoords = Table[GeoPositionXYZ[xyzCoords[[i]], "ITRF00"], {i, Length@xyzCoords}];
    latlongCoords = Table[GeoPosition@latlongCoords[[i]], {i, Length@xyzCoords}];
    latlongCoords = Table[GeoMarker@latlongCoords[[i]], {i, Length@xyzCoords}];
    outtype = ChoiceDialog["Type of map?", {"2D" -> 1, "3D" -> 2}];
     1, GeoGraphics[latlongCoords, GeoRange -> "World", GeoProjection -> "Robinson"],
     2, Graphics3D[{PointSize@Large,
           Point@Table[Normalize@xyzCoords[[i]], {i, Length@xyzCoords}],
           Opacity@0.5, Sphere[]}]

These are the ITRF00 coordinates for Brazilia, Berlin and New Delhi. You can input them in one go, selecting the "All" alternative and paste:

{{4115144, -4555919, -1723314}, {3783638, 899994, 5038219}, {1239693, 5465361, 3035052}}
POSTED BY: Hans Milton

Thank you. It works. And now it's time to adapt it. Here's the thing... I am an undergrad researcher and this is part of a research project. I have studied this code, I know how it works, and even learned some new commands, which is the point of doing research. Thank you much. I made a few small changes to the code in (* *) to document it... and now the next step is to adapt it to take data from GPS files in order to map the locations of the satellites in the GPS constellation. (those are given in ITRF, hence the need to have ITRF inputs.) Programming is always easiest when divided into steps and thanks so much for helping me with the most important step. I posted many questions and I thank everyone who helped. I will ask the professor if we can put your names right next to mine in the list when the final code is assembled from everyone's tidbits.

POSTED BY: Nathan Lundholm

The new code doesn't work either... it's putting an XYZ cartesian point in latlonlist. It needs to convert the cartesian point to a latitude/longitude/height point first. I've tried 50 times and can't implement the conversion. Please help again.

POSTED BY: Nathan Lundholm
Posted 8 years ago

A number of typos and misunderstandings and missing semicolons, all of which cause problems.

Compare this, character by character with your original and track down why each change is there

xlist = {};
ylist = {};
zlist = {};
latlonlist = {};
x = Input["What is the x coordinate?"];
y = Input["What is the y coordinate?"];
z = Input["What is the z coordinate?"];
AppendTo[xlist, x];
AppendTo[ylist, y];
AppendTo[zlist, z];
   again = InputString["Enter more coords? Y for yes, N for no"];
   If[again == "Y", Print["Okay!"]; Goto[startinput]];
   If[again != "N", Print["Sorry, this is an invalid input here!"];
   Goto[errorcontrol]]; If[again == "N", Print["Okay."]]));
list = Transpose[{xlist, ylist, zlist}];
qty = Length[list];
For[i = 1, i <= qty, i++,
   point = Part[list, i];
   AppendTo[latlonlist, GeoMarker[GeoPosition[point]]];
GeoGraphics[latlonlist, GeoRange -> "World", GeoProjection -> "Robinson"]
ListPointPlot3D[list, DataRange -> {{-1000000, 1000000}, {-1000000, 1000000}}]
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract