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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript