Color terrain on SpatialLines object made of sparse Lines Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!Write lines of text to a file in RRun R script from command lineHow to create SpatialLine objectPoint Pattern AnalysisValue of coordinates() for a SpatialPolygonsDataFrame object?How to make a SpatialLines object from undefined - but known - spatial sequence of points in R?Apply Data to SpatialLines Objectlabeling/ coloring elements/segments of a linnet objectR: Union Spatial Polygons won't remove separation line completelySpatial line start and end point in R

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

Is the address of a local variable a constexpr?

What would be the ideal power source for a cybernetic eye?

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

How do I keep my slimes from escaping their pens?

When -s is used with third person singular. What's its use in this context?

Letter Boxed validator

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

How can players work together to take actions that are otherwise impossible?

Diagram with tikz

Does accepting a pardon have any bearing on trying that person for the same crime in a sovereign jurisdiction?

List *all* the tuples!

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

Using et al. for a last / senior author rather than for a first author

Did Kevin spill real chili?

How widely used is the term Treppenwitz? Is it something that most Germans know?

Is there any avatar supposed to be born between the death of Krishna and the birth of Kalki?

3 doors, three guards, one stone

Single word antonym of "flightless"

Why are there no cargo aircraft with "flying wing" design?

Why is "Consequences inflicted." not a sentence?

What is this single-engine low-wing propeller plane?

Bonus calculation: Am I making a mountain out of a molehill?

How do I mention the quality of my school without bragging



Color terrain on SpatialLines object made of sparse Lines



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!Write lines of text to a file in RRun R script from command lineHow to create SpatialLine objectPoint Pattern AnalysisValue of coordinates() for a SpatialPolygonsDataFrame object?How to make a SpatialLines object from undefined - but known - spatial sequence of points in R?Apply Data to SpatialLines Objectlabeling/ coloring elements/segments of a linnet objectR: Union Spatial Polygons won't remove separation line completelySpatial line start and end point in R



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a high-resolution coastline shapefile from NOAA that covers a large chunk of the globe. My aim is to:



1 - Clip this dataset to a smaller area (already achieved OK);
2 - Overlay the bounded area on a base R plot (still having problems).



Here's my code:



library(rgeos)
library(rgdal)

download.file(url = 'https://dnc.nga.mil/DNCSiteContent/Shapefiles/shapefile01.zip', destfile = '~/Desktop/shapefile01.zip')
unzip('~/Desktop/shapefile01.zip', exdir = '~/Desktop/shapefile01')
closeAllConnections()
system('rm -rf ~/Desktop/shapefile01.zip')
targetfolder <- dir('~/Desktop', pattern = 'shapefile01', full.names = TRUE) # need full directory path for rgdal::readOGR

shape <- rgdal::readOGR(dsn = targetfolder, layer = 'cd01')
bbx <- rgeos::readWKT('POLYGON((-42.05 -23.03, -41.95 -23.03, -41.95 -22.93, -42.05 -22.93, -42.05 -23.03))')
proj4string(bbx) <- proj4string(shape)
mysite <- rgeos::gIntersection(shape, bbx)
plot(mysite)


enter image description here



What I ideally want here is to color the terrain on the map, such that it would look like this (here edited with Photoshop):



enter image description here



But mysite, an object of class SpatialLines with 28 line segments that should be a single thing, but in reality are not connected. So when I plot the whole object, the line contour of this coastal area appears to be just fine. But because they're a bunch of smaller line segments, R doesn't know how to put them together so I can fill the terrain. Is there a way to tell R to color fill the continent? Maybe combine all these segments into one continuous continental contour?



By the way, I would ideally like to do this in base R because this will be later added (i.e. overlaid) onto another plot with a color gradient fill for the ocean around the same geographical area (generated from another spatial file).



UPDATE



Using the spatstat package I can now visualise all the line segments very easily, so I thought it would be nice to update this here to help visualise the problem. Here's the code:



library(spatstat)
mysite2 <- spatstat::as.psp(mysite)
plot(mysite2)


enter image description here



Makes sense? I think it would be nice to have a permanent solution because that's the nature of these high-res shoreline shapefiles provided by NOAA.










share|improve this question
























  • In general, for a given shoreline, how do you know which direction the sea is and which direction is land? Do any shapefiles or rasters exist for the land and sea?

    – awchisholm
    Mar 23 at 12:05


















0















I have a high-resolution coastline shapefile from NOAA that covers a large chunk of the globe. My aim is to:



1 - Clip this dataset to a smaller area (already achieved OK);
2 - Overlay the bounded area on a base R plot (still having problems).



Here's my code:



library(rgeos)
library(rgdal)

download.file(url = 'https://dnc.nga.mil/DNCSiteContent/Shapefiles/shapefile01.zip', destfile = '~/Desktop/shapefile01.zip')
unzip('~/Desktop/shapefile01.zip', exdir = '~/Desktop/shapefile01')
closeAllConnections()
system('rm -rf ~/Desktop/shapefile01.zip')
targetfolder <- dir('~/Desktop', pattern = 'shapefile01', full.names = TRUE) # need full directory path for rgdal::readOGR

shape <- rgdal::readOGR(dsn = targetfolder, layer = 'cd01')
bbx <- rgeos::readWKT('POLYGON((-42.05 -23.03, -41.95 -23.03, -41.95 -22.93, -42.05 -22.93, -42.05 -23.03))')
proj4string(bbx) <- proj4string(shape)
mysite <- rgeos::gIntersection(shape, bbx)
plot(mysite)


enter image description here



What I ideally want here is to color the terrain on the map, such that it would look like this (here edited with Photoshop):



enter image description here



But mysite, an object of class SpatialLines with 28 line segments that should be a single thing, but in reality are not connected. So when I plot the whole object, the line contour of this coastal area appears to be just fine. But because they're a bunch of smaller line segments, R doesn't know how to put them together so I can fill the terrain. Is there a way to tell R to color fill the continent? Maybe combine all these segments into one continuous continental contour?



By the way, I would ideally like to do this in base R because this will be later added (i.e. overlaid) onto another plot with a color gradient fill for the ocean around the same geographical area (generated from another spatial file).



UPDATE



Using the spatstat package I can now visualise all the line segments very easily, so I thought it would be nice to update this here to help visualise the problem. Here's the code:



library(spatstat)
mysite2 <- spatstat::as.psp(mysite)
plot(mysite2)


enter image description here



Makes sense? I think it would be nice to have a permanent solution because that's the nature of these high-res shoreline shapefiles provided by NOAA.










share|improve this question
























  • In general, for a given shoreline, how do you know which direction the sea is and which direction is land? Do any shapefiles or rasters exist for the land and sea?

    – awchisholm
    Mar 23 at 12:05














0












0








0








I have a high-resolution coastline shapefile from NOAA that covers a large chunk of the globe. My aim is to:



1 - Clip this dataset to a smaller area (already achieved OK);
2 - Overlay the bounded area on a base R plot (still having problems).



Here's my code:



library(rgeos)
library(rgdal)

download.file(url = 'https://dnc.nga.mil/DNCSiteContent/Shapefiles/shapefile01.zip', destfile = '~/Desktop/shapefile01.zip')
unzip('~/Desktop/shapefile01.zip', exdir = '~/Desktop/shapefile01')
closeAllConnections()
system('rm -rf ~/Desktop/shapefile01.zip')
targetfolder <- dir('~/Desktop', pattern = 'shapefile01', full.names = TRUE) # need full directory path for rgdal::readOGR

shape <- rgdal::readOGR(dsn = targetfolder, layer = 'cd01')
bbx <- rgeos::readWKT('POLYGON((-42.05 -23.03, -41.95 -23.03, -41.95 -22.93, -42.05 -22.93, -42.05 -23.03))')
proj4string(bbx) <- proj4string(shape)
mysite <- rgeos::gIntersection(shape, bbx)
plot(mysite)


enter image description here



What I ideally want here is to color the terrain on the map, such that it would look like this (here edited with Photoshop):



enter image description here



But mysite, an object of class SpatialLines with 28 line segments that should be a single thing, but in reality are not connected. So when I plot the whole object, the line contour of this coastal area appears to be just fine. But because they're a bunch of smaller line segments, R doesn't know how to put them together so I can fill the terrain. Is there a way to tell R to color fill the continent? Maybe combine all these segments into one continuous continental contour?



By the way, I would ideally like to do this in base R because this will be later added (i.e. overlaid) onto another plot with a color gradient fill for the ocean around the same geographical area (generated from another spatial file).



UPDATE



Using the spatstat package I can now visualise all the line segments very easily, so I thought it would be nice to update this here to help visualise the problem. Here's the code:



library(spatstat)
mysite2 <- spatstat::as.psp(mysite)
plot(mysite2)


enter image description here



Makes sense? I think it would be nice to have a permanent solution because that's the nature of these high-res shoreline shapefiles provided by NOAA.










share|improve this question
















I have a high-resolution coastline shapefile from NOAA that covers a large chunk of the globe. My aim is to:



1 - Clip this dataset to a smaller area (already achieved OK);
2 - Overlay the bounded area on a base R plot (still having problems).



Here's my code:



library(rgeos)
library(rgdal)

download.file(url = 'https://dnc.nga.mil/DNCSiteContent/Shapefiles/shapefile01.zip', destfile = '~/Desktop/shapefile01.zip')
unzip('~/Desktop/shapefile01.zip', exdir = '~/Desktop/shapefile01')
closeAllConnections()
system('rm -rf ~/Desktop/shapefile01.zip')
targetfolder <- dir('~/Desktop', pattern = 'shapefile01', full.names = TRUE) # need full directory path for rgdal::readOGR

shape <- rgdal::readOGR(dsn = targetfolder, layer = 'cd01')
bbx <- rgeos::readWKT('POLYGON((-42.05 -23.03, -41.95 -23.03, -41.95 -22.93, -42.05 -22.93, -42.05 -23.03))')
proj4string(bbx) <- proj4string(shape)
mysite <- rgeos::gIntersection(shape, bbx)
plot(mysite)


enter image description here



What I ideally want here is to color the terrain on the map, such that it would look like this (here edited with Photoshop):



enter image description here



But mysite, an object of class SpatialLines with 28 line segments that should be a single thing, but in reality are not connected. So when I plot the whole object, the line contour of this coastal area appears to be just fine. But because they're a bunch of smaller line segments, R doesn't know how to put them together so I can fill the terrain. Is there a way to tell R to color fill the continent? Maybe combine all these segments into one continuous continental contour?



By the way, I would ideally like to do this in base R because this will be later added (i.e. overlaid) onto another plot with a color gradient fill for the ocean around the same geographical area (generated from another spatial file).



UPDATE



Using the spatstat package I can now visualise all the line segments very easily, so I thought it would be nice to update this here to help visualise the problem. Here's the code:



library(spatstat)
mysite2 <- spatstat::as.psp(mysite)
plot(mysite2)


enter image description here



Makes sense? I think it would be nice to have a permanent solution because that's the nature of these high-res shoreline shapefiles provided by NOAA.







r sp rgdal spatstat rgeo-shapefile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 8:53







dbarneche

















asked Mar 22 at 8:38









dbarnechedbarneche

148126




148126












  • In general, for a given shoreline, how do you know which direction the sea is and which direction is land? Do any shapefiles or rasters exist for the land and sea?

    – awchisholm
    Mar 23 at 12:05


















  • In general, for a given shoreline, how do you know which direction the sea is and which direction is land? Do any shapefiles or rasters exist for the land and sea?

    – awchisholm
    Mar 23 at 12:05

















In general, for a given shoreline, how do you know which direction the sea is and which direction is land? Do any shapefiles or rasters exist for the land and sea?

– awchisholm
Mar 23 at 12:05






In general, for a given shoreline, how do you know which direction the sea is and which direction is land? Do any shapefiles or rasters exist for the land and sea?

– awchisholm
Mar 23 at 12:05













0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f55295733%2fcolor-terrain-on-spatiallines-object-made-of-sparse-lines%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • 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%2fstackoverflow.com%2fquestions%2f55295733%2fcolor-terrain-on-spatiallines-object-made-of-sparse-lines%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

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?