For loop within GeoGraphics











up vote
2
down vote

favorite












I'm trying to plot a map with a list of destinations as Disks.



I first input the cities into a list such as:



destinations = {GeoPosition[New York City],
GeoPosition[Mumbai],
...}


where "New York City" is input using the Ctrl+= method to access interpreter and specify it as a city.



Then I have something summarizing to:



GeoGraphics[{
Black,
Disk[For[i=1, i<Length[destinations]+1,i++,destinations[[i]],1],
...
Disk[city,1],
},
...
]


This outputs a map with my desired projection settings such as background, range, and the single disk that I specified separately like:



Disk[city,1],


I have also tried to put the Disk function inside a for loop like:



For[i=1, i<Length[destinations]+1,i++,Disk[destinations[[i]],1]],


It's not an incorrect indexing of the destinations list either, because



For[i=1, i<Length[destinations]+1,i++,Print[destinations[[i]]]]


outputs the correct amount of cities, whereas



For[i=0, i<Length[destinations],i++,Print[destinations[[i]]]]


outputs a first item of "List" and doesn't print the last city.



Is it possible to use for loops within a GeoGraphics function, or would I be required to add a Disk function line for each item I would like to plot instead of iterating through a list?



Thanks in advance for the help!










share|improve this question




























    up vote
    2
    down vote

    favorite












    I'm trying to plot a map with a list of destinations as Disks.



    I first input the cities into a list such as:



    destinations = {GeoPosition[New York City],
    GeoPosition[Mumbai],
    ...}


    where "New York City" is input using the Ctrl+= method to access interpreter and specify it as a city.



    Then I have something summarizing to:



    GeoGraphics[{
    Black,
    Disk[For[i=1, i<Length[destinations]+1,i++,destinations[[i]],1],
    ...
    Disk[city,1],
    },
    ...
    ]


    This outputs a map with my desired projection settings such as background, range, and the single disk that I specified separately like:



    Disk[city,1],


    I have also tried to put the Disk function inside a for loop like:



    For[i=1, i<Length[destinations]+1,i++,Disk[destinations[[i]],1]],


    It's not an incorrect indexing of the destinations list either, because



    For[i=1, i<Length[destinations]+1,i++,Print[destinations[[i]]]]


    outputs the correct amount of cities, whereas



    For[i=0, i<Length[destinations],i++,Print[destinations[[i]]]]


    outputs a first item of "List" and doesn't print the last city.



    Is it possible to use for loops within a GeoGraphics function, or would I be required to add a Disk function line for each item I would like to plot instead of iterating through a list?



    Thanks in advance for the help!










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm trying to plot a map with a list of destinations as Disks.



      I first input the cities into a list such as:



      destinations = {GeoPosition[New York City],
      GeoPosition[Mumbai],
      ...}


      where "New York City" is input using the Ctrl+= method to access interpreter and specify it as a city.



      Then I have something summarizing to:



      GeoGraphics[{
      Black,
      Disk[For[i=1, i<Length[destinations]+1,i++,destinations[[i]],1],
      ...
      Disk[city,1],
      },
      ...
      ]


      This outputs a map with my desired projection settings such as background, range, and the single disk that I specified separately like:



      Disk[city,1],


      I have also tried to put the Disk function inside a for loop like:



      For[i=1, i<Length[destinations]+1,i++,Disk[destinations[[i]],1]],


      It's not an incorrect indexing of the destinations list either, because



      For[i=1, i<Length[destinations]+1,i++,Print[destinations[[i]]]]


      outputs the correct amount of cities, whereas



      For[i=0, i<Length[destinations],i++,Print[destinations[[i]]]]


      outputs a first item of "List" and doesn't print the last city.



      Is it possible to use for loops within a GeoGraphics function, or would I be required to add a Disk function line for each item I would like to plot instead of iterating through a list?



      Thanks in advance for the help!










      share|improve this question















      I'm trying to plot a map with a list of destinations as Disks.



      I first input the cities into a list such as:



      destinations = {GeoPosition[New York City],
      GeoPosition[Mumbai],
      ...}


      where "New York City" is input using the Ctrl+= method to access interpreter and specify it as a city.



      Then I have something summarizing to:



      GeoGraphics[{
      Black,
      Disk[For[i=1, i<Length[destinations]+1,i++,destinations[[i]],1],
      ...
      Disk[city,1],
      },
      ...
      ]


      This outputs a map with my desired projection settings such as background, range, and the single disk that I specified separately like:



      Disk[city,1],


      I have also tried to put the Disk function inside a for loop like:



      For[i=1, i<Length[destinations]+1,i++,Disk[destinations[[i]],1]],


      It's not an incorrect indexing of the destinations list either, because



      For[i=1, i<Length[destinations]+1,i++,Print[destinations[[i]]]]


      outputs the correct amount of cities, whereas



      For[i=0, i<Length[destinations],i++,Print[destinations[[i]]]]


      outputs a first item of "List" and doesn't print the last city.



      Is it possible to use for loops within a GeoGraphics function, or would I be required to add a Disk function line for each item I would like to plot instead of iterating through a list?



      Thanks in advance for the help!







      list-manipulation geographics






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 at 21:08









      kglr

      175k9197402




      175k9197402










      asked Nov 29 at 20:02









      Reedinationer

      415




      415






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote













          You don't need For loops.



          Instead you can Map Disk on destinations; that is, use Disk /@ destionations (Disk[#, 5]& /@ destionations if you want a radius of 5 instead of the default radius 1).



          cities = {Entity["City", {"NewYork", "NewYork", "UnitedStates"}], 
          Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}],
          Entity["City", {"Bombay", "Maharashtra", "India"}],
          Entity["City", {"Delhi", "Delhi", "India"}]};
          destinations = GeoPosition /@ cities;

          GeoGraphics[{Black, Disk /@ destinations}]


          enter image description here



          Notes: If you have to use a For loop you can do:



          disks = {}; 
          For[i = 1, i <= Length[destinations], i++, AppendTo[disks, Disk[destinations[[i]]]]];
          GeoGraphics[{Black, disks}]



          same picture




          Alternatively, you can use Table:



          Table[Disk[i], {i, destinations}] == disks



          True




          and if you have to use a For loop inside GeoGraphics



          GeoGraphics[{Black, disks = {}; 
          For[i = 1, i <= Length[destinations], i++,
          AppendTo[disks, Disk[destinations[[i]]]]]; disks}]



          same picture







          share|improve this answer























          • Yes, this works perfectly thank you!
            – Reedinationer
            Nov 29 at 22:07











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "387"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186998%2ffor-loop-within-geographics%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          5
          down vote













          You don't need For loops.



          Instead you can Map Disk on destinations; that is, use Disk /@ destionations (Disk[#, 5]& /@ destionations if you want a radius of 5 instead of the default radius 1).



          cities = {Entity["City", {"NewYork", "NewYork", "UnitedStates"}], 
          Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}],
          Entity["City", {"Bombay", "Maharashtra", "India"}],
          Entity["City", {"Delhi", "Delhi", "India"}]};
          destinations = GeoPosition /@ cities;

          GeoGraphics[{Black, Disk /@ destinations}]


          enter image description here



          Notes: If you have to use a For loop you can do:



          disks = {}; 
          For[i = 1, i <= Length[destinations], i++, AppendTo[disks, Disk[destinations[[i]]]]];
          GeoGraphics[{Black, disks}]



          same picture




          Alternatively, you can use Table:



          Table[Disk[i], {i, destinations}] == disks



          True




          and if you have to use a For loop inside GeoGraphics



          GeoGraphics[{Black, disks = {}; 
          For[i = 1, i <= Length[destinations], i++,
          AppendTo[disks, Disk[destinations[[i]]]]]; disks}]



          same picture







          share|improve this answer























          • Yes, this works perfectly thank you!
            – Reedinationer
            Nov 29 at 22:07















          up vote
          5
          down vote













          You don't need For loops.



          Instead you can Map Disk on destinations; that is, use Disk /@ destionations (Disk[#, 5]& /@ destionations if you want a radius of 5 instead of the default radius 1).



          cities = {Entity["City", {"NewYork", "NewYork", "UnitedStates"}], 
          Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}],
          Entity["City", {"Bombay", "Maharashtra", "India"}],
          Entity["City", {"Delhi", "Delhi", "India"}]};
          destinations = GeoPosition /@ cities;

          GeoGraphics[{Black, Disk /@ destinations}]


          enter image description here



          Notes: If you have to use a For loop you can do:



          disks = {}; 
          For[i = 1, i <= Length[destinations], i++, AppendTo[disks, Disk[destinations[[i]]]]];
          GeoGraphics[{Black, disks}]



          same picture




          Alternatively, you can use Table:



          Table[Disk[i], {i, destinations}] == disks



          True




          and if you have to use a For loop inside GeoGraphics



          GeoGraphics[{Black, disks = {}; 
          For[i = 1, i <= Length[destinations], i++,
          AppendTo[disks, Disk[destinations[[i]]]]]; disks}]



          same picture







          share|improve this answer























          • Yes, this works perfectly thank you!
            – Reedinationer
            Nov 29 at 22:07













          up vote
          5
          down vote










          up vote
          5
          down vote









          You don't need For loops.



          Instead you can Map Disk on destinations; that is, use Disk /@ destionations (Disk[#, 5]& /@ destionations if you want a radius of 5 instead of the default radius 1).



          cities = {Entity["City", {"NewYork", "NewYork", "UnitedStates"}], 
          Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}],
          Entity["City", {"Bombay", "Maharashtra", "India"}],
          Entity["City", {"Delhi", "Delhi", "India"}]};
          destinations = GeoPosition /@ cities;

          GeoGraphics[{Black, Disk /@ destinations}]


          enter image description here



          Notes: If you have to use a For loop you can do:



          disks = {}; 
          For[i = 1, i <= Length[destinations], i++, AppendTo[disks, Disk[destinations[[i]]]]];
          GeoGraphics[{Black, disks}]



          same picture




          Alternatively, you can use Table:



          Table[Disk[i], {i, destinations}] == disks



          True




          and if you have to use a For loop inside GeoGraphics



          GeoGraphics[{Black, disks = {}; 
          For[i = 1, i <= Length[destinations], i++,
          AppendTo[disks, Disk[destinations[[i]]]]]; disks}]



          same picture







          share|improve this answer














          You don't need For loops.



          Instead you can Map Disk on destinations; that is, use Disk /@ destionations (Disk[#, 5]& /@ destionations if you want a radius of 5 instead of the default radius 1).



          cities = {Entity["City", {"NewYork", "NewYork", "UnitedStates"}], 
          Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}],
          Entity["City", {"Bombay", "Maharashtra", "India"}],
          Entity["City", {"Delhi", "Delhi", "India"}]};
          destinations = GeoPosition /@ cities;

          GeoGraphics[{Black, Disk /@ destinations}]


          enter image description here



          Notes: If you have to use a For loop you can do:



          disks = {}; 
          For[i = 1, i <= Length[destinations], i++, AppendTo[disks, Disk[destinations[[i]]]]];
          GeoGraphics[{Black, disks}]



          same picture




          Alternatively, you can use Table:



          Table[Disk[i], {i, destinations}] == disks



          True




          and if you have to use a For loop inside GeoGraphics



          GeoGraphics[{Black, disks = {}; 
          For[i = 1, i <= Length[destinations], i++,
          AppendTo[disks, Disk[destinations[[i]]]]]; disks}]



          same picture








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 29 at 21:05

























          answered Nov 29 at 20:44









          kglr

          175k9197402




          175k9197402












          • Yes, this works perfectly thank you!
            – Reedinationer
            Nov 29 at 22:07


















          • Yes, this works perfectly thank you!
            – Reedinationer
            Nov 29 at 22:07
















          Yes, this works perfectly thank you!
          – Reedinationer
          Nov 29 at 22:07




          Yes, this works perfectly thank you!
          – Reedinationer
          Nov 29 at 22:07


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematica Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f186998%2ffor-loop-within-geographics%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар