<html style="direction: ltr;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style id="bidiui-paragraph-margins" type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
</head>
<body bidimailui-charset-is-forced="true" style="direction: ltr;">
<p><font size="4"><font face="Helvetica, Arial, sans-serif">(cc-ing
the r-sig-geo maillist)</font></font></p>
<p><br>
</p>
<div class="moz-cite-prefix">On 22/10/2022 13:52, Nick Wray wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CABxY9BPCOiQjJskYY86qqehOCy8OLQRRkKg_yqeNKE6oEHy25Q@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Hi Micha Thanks for your ideas which I will look
into I hadn't heard of r-sig-geo before but I've signed up to
it. I'm a bit of beginner as far as geospatial in R goes. What
I am ultimately trying to do is this - my PhD research is into
the relative proportions of the effects of climate change and
land use on streamflow in Scottish rivers (I'm based at
Edinburgh) and to this end I need to create a map of catchments
eg the Tweed onto which I can placing flow gauging stations/
weather stations etc . I have catchment outline shapefiles and
the stations but finding the bit of the whole of the UK river
system shapefile which is the Tweed catchment is tricky, as the
shapefile matrix doesn't have names in it and I am trying to
identify the Tweed and its tributaries from the coordinates of
its mouth sources and so on... that's why i need to pull out
the coordinates. Any suggestions 'd be v welcome </div>
</blockquote>
<p><br>
</p>
<p>So you have a polygon shapefile of the "Tweed" catchment, and a
line vector shapefile of all UK rivers. Is that correct so far?
Then you need to intersect the UK rivers with the Tweed polygon to
obtain tweed rivers.</p>
<p><br>
</p>
<p>In that case:</p>
<p><br>
</p>
<p>library(sf)<br>
</p>
<p>uk_rivers <- st_read(dsn="path/to/rivers.shp")</p>
<p>tweed <- st_read(dsn="path/to/tweed.shp)</p>
<p>tweed_rivers = st_intersection(uk_rivers, tweed)</p>
<p><br>
</p>
<p>The tweed_rivers result should be a line feature of rivers inside
the tweed polygon. The result should have the same attribute
columns as the uk_rivers. So if the UK rivers has an attribute
column with names, then the result should have the same names.<br>
</p>
<p><br>
</p>
<p>HTH</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:CABxY9BPCOiQjJskYY86qqehOCy8OLQRRkKg_yqeNKE6oEHy25Q@mail.gmail.com">
<div dir="ltr">Nick</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Sat, 22 Oct 2022 at 10:28,
Micha Silver <<a href="mailto:tsvibar@gmail.com"
moz-do-not-send="true" class="moz-txt-link-freetext">tsvibar@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello
Nick:<br>
<br>
<br>
First: as Jeff pointed out, you'll probably have better luck
posting to <br>
the r-sig-geo list.<br>
<br>
<br>
On 21/10/2022 14:25, Nick Wray wrote:<br>
> Hello<br>
><br>
> I have managed to download and plot the outline for the
River Tweed In the<br>
> Sottish borders) catchment using this code. 21009 is a
zipfile downloaded<br>
> from the FEH website <a
href="https://fehweb.ceh.ac.uk/Map" rel="noreferrer"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://fehweb.ceh.ac.uk/Map</a>:<br>
><br>
> require(rgdal)<br>
><br>
> shape <- readOGR(dsn ="C:/Users/nick/Desktop/PhD Oct
22", layer = "21009")<br>
<br>
<br>
Second: The R-spatial "ecosystem" has undergone some major
changes <br>
recent years. You'd be well advised, I think, to switch to
using the <br>
`sf` package for vector data. So reading in a shapefile would
be <br>
`sf::st_read(dsn="...")`<br>
<br>
<br>
<br>
Third: Regarding your other post about string representations
of <br>
geometries. Can you be more specific as to what your final
goal is? The <br>
"canonical" string representation of geometries is Well Known
Text (WKT) <br>
and can be returned with the `sf::st_as_text()` function. Does
that help?<br>
<br>
<br>
Kind regards,<br>
<br>
Micha<br>
<br>
<br>
> shape<br>
><br>
> plot(shape)<br>
><br>
> and I get an outline of the Tweed catchment which I can
use<br>
><br>
> the zipfile has eight documents all with the name
“21009.” and the suffixes<br>
> cpg/dbf/prj/sbn/sbx/shp/shp/shx There are two .shp
docs, one labelled as<br>
> SHP file and one as XML file.<br>
><br>
> However<br>
><br>
> I then have downloaded a file of a plot of all the rivers
in the uk from<br>
> <a href="https://osdatahub.os.uk/downloads/open"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://osdatahub.os.uk/downloads/open</a><br>
><br>
> I’ve put this data into a zipfile with the name “rivers”
Within this are<br>
> eight docs – four with the names HydroNode. and suffixes
dbf/prj/shp/shx<br>
> and four with the name WatercourseLink. and the four
suffixes.<br>
><br>
> Just subbing in “rivers” for “21009” in my code above
doesn’t work and I<br>
> can’t find a way of getting into the shapefiles and
opening them<br>
><br>
><br>
> I'd be grateful if anyone can help me get further with
this<br>
><br>
> Thanks Nick Wray<br>
><br>
> [[alternative HTML version deleted]]<br>
><br>
> ______________________________________________<br>
> <a href="mailto:R-help@r-project.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">R-help@r-project.org</a>
mailing list -- To UNSUBSCRIBE and more, see<br>
> <a href="https://stat.ethz.ch/mailman/listinfo/r-help"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://stat.ethz.ch/mailman/listinfo/r-help</a><br>
> PLEASE do read the posting guide <a
href="http://www.R-project.org/posting-guide.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://www.R-project.org/posting-guide.html</a><br>
> and provide commented, minimal, self-contained,
reproducible code.<br>
<br>
-- <br>
Micha Silver<br>
Ben Gurion Univ.<br>
Sde Boker, Remote Sensing Lab<br>
cell: +972-523-665918<br>
<br>
</blockquote>
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
</body>
</html>