Message Boards Message Boards

0
|
8729 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Polygon Texture

Hi, I am trying to put the US flag (using Texture function) on top of US map (using CountryData function). Nevertheless, the map I obtain is completely dark. Here it is what I am trying: Set the variable fig equal to the American flag found in here:

https://en.wikipedia.org/wiki/Flag_of_the_United_States#/\media/File:Flag_of_the_United_States.svg

Graphics[{Texture[fig], CountryData["UnitedStates", "Polygon"]}]

In my understanding, the problem might be coming from the fact that CountryDate is returning a Polygon. So I tried to follow the help example and it worked fine:

Graphics3D[{Texture[fig], Polygon[{{-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, Lighting -> "Neutral"]

Does anyone know how can I fix this? Thanks in advance!

POSTED BY: Diogo Duarte
4 Replies

Sorry, I just looked up Texture in the Mathematica documentation center. I wonder if Texture works also with GeoGraphics, which would be better in your case.

POSTED BY: Gianluca Gorni

In GeoGraphics the recommended way is using GeoStyling, which depeding on what you want as output, you can use "GeoImage" or "Image":

GeoGraphics[{GeoStyling[{"GeoImage", 
    Rasterize[CountryData["UnitedStates", "Flag"], "Image", 
     ImageSize -> 400]}], Polygon[Entity["Country", "UnitedStates"]]}]

USA flag map GeoImage

GeoGraphics[{GeoStyling[{"Image", 
    Rasterize[CountryData["UnitedStates", "Flag"], "Image", 
     ImageSize -> 400]}], Polygon[Entity["Country", "UnitedStates"]]}]

USA flag map Image

Hi Gianluca, thanks for putting me on the right track. I modified your code a little bit to end up with the map with the right rotation and put the flag on the right direction. Here it is how I adapted your solution:

coord = CountryData["UnitedStates", "Coordinates"][[1]];
 Rotate[ImageReflect[Graphics[{Texture[ CountryData["UnitedStates", "Flag"]], Polygon[coord, 
  VertexTextureCoordinates -> -Transpose[{Rescale[
       coord[[All, 1]]], Rescale[coord[[All, 2]]]}]]}],Left -> Right], -\[Pi]/2]

There might be a better way to do it without using ImageReflect but this was the only way I manage to do it. If you have any good reference for learning Polygon and Texture manipulation, it will be deeply appreciated. Many thanks.

UPDATED: Here it is some improvement I managed to implement:

coord = CountryData["UnitedStates", "Coordinates"][[1]].{{-1, 0}, {0,1}}.{{0, -1}, {1, 0}};
Graphics[{Opacity[0.5], Texture[CountryData["UnitedStates", "Flag"]], Polygon[coord,VertexTextureCoordinates ->Transpose[{Rescale[coord[[All, 1]]], Rescale[coord[[All, 2]]]}]]}]
POSTED BY: Diogo Duarte

This needs some work, but it may get you started:

coord = CountryData["UnitedStates", "SchematicCoordinates"][[1]];
Rotate[Graphics[{Texture[CountryData["UnitedStates", "Flag"]], 
   Polygon[coord, 
    VertexTextureCoordinates -> 
     Transpose[{Rescale[coord[[All, 1]]], 
       Rescale[coord[[All, 2]]]}]]}], Pi/2]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract