New version of package gDefrag
<p class="has-text-align-justify">We have developed a new version of the gDefrag package. The previous version has been retired from CRAN due to dependencies on outdated packages. <strong>This updated version is still under development and may contain limitations. Please exercise caution when using it</strong>. I have just uploaded a <strong>new version of the package gDefrag</strong> on <a href="https://github.com/FMestre1/gDefrag" rel="noreferrer noopener" target="_blank">GitHub</a>. It will still be some time for it to go to CRAN again.</p>
<p><strong>What is the package all about?</strong></p>
<p class="has-text-align-justify">Roads (and other linear infrastructures) fragment natural habitats. <strong>This package provides a set of tools to help the de-fragmentation process</strong>. It works by prioritizing the different sections of linear infrastructures (e.g. roads, power lines) to increase the available amount of a given resource (e.g. habitat).</p>
<p class="has-text-align-justify">If you want to know more, we published a paper <a href="https://doi.org/10.1016/j.ecolmodel.2018.10.012">describing the package</a> and another <a href="https://doi.org/10.1016/j.landurbplan.2019.103653" rel="noreferrer noopener" target="_blank">demonstrating its usability</a>. Additionally <a href="https://www.researchgate.net/publication/325260755_Package_'gDefrag'_Title_Graph-Based_Landscape_De-Fragmentation" rel="noreferrer noopener" target="_blank">here’s the manual</a> of a previous version.</p>
<p><strong>Demonstration</strong></p>
<p>Let’s begin with a brief demosntration. The first step is the <strong>installation</strong> of the package:</p>
<ol class="wp-block-list"></ol>
<ol class="wp-block-list"></ol>
<pre class="wp-block-code"><code>library(devtools)
devtools::install_github("FMestre1/gDefrag") </code></pre>
<p class="has-text-align-justify">Then, <strong>manually download the shapefile files from our sample dataset</strong>. Go to <a href="https://github.com/FMestre1/gDefrag/tree/master/data" rel="noreferrer noopener" target="_blank">this link</a> and download all files (<code>road_P.shp</code>, <code>road_P.shx</code>, <code>road_P.dbf</code>, <code>road_P.prj</code>, etc.).</p>
<p><strong>Load </strong>them to your environment:</p>
<pre class="wp-block-code"><code>road_P <- terra::vect("road_P.shp")
</code></pre>
<p>The next step is obtaining a vector file of the nodes, by running the function <strong>node.creation</strong>:</p>
<pre class="wp-block-code"><code>out1 <- node.creation(land_polyg = road_P, value_col = "frst_sm", scale_nodes = 10, col_nodes = "pink", cex_labels = 1)</code></pre>
<p>This will create a <strong>SpatVector object and plot the following figure</strong>:</p>
<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img alt="" class="wp-image-2345" data-attachment-id="2345" data-comments-opened="1" data-image-caption="" data-image-description="" data-image-meta='{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}' data-image-title="image" data-large-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png?w=640" data-medium-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png?w=300" data-orig-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png" data-orig-size="1920,975" data-permalink="https://geekcologist.wordpress.com/2025/02/05/new-version-of-package-gdefrag/image-9/" height="520" sizes="(max-width: 1024px) 100vw, 1024px" src="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png?w=1024" srcset="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png?w=1024 1024w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png?w=150 150w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png?w=300 300w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png?w=768 768w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image.png 1920w" style="width:587px;height:auto" width="1024"/></figure></div>
<p>Then you have to <strong>create the edges spatVector</strong> by running edge.creation:</p>
<pre class="wp-block-code"><code>out2 <- edge.creation(nodes = out1, land_polyg = road_P, min_length = 0, min_pol_area = 0)</code></pre>
<p>Which will create teh following plot, with the edges in blue:</p>
<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img alt="" class="wp-image-2348" data-attachment-id="2348" data-comments-opened="1" data-image-caption="" data-image-description="" data-image-meta='{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}' data-image-title="image" data-large-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png?w=640" data-medium-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png?w=300" data-orig-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png" data-orig-size="1920,975" data-permalink="https://geekcologist.wordpress.com/2025/02/05/new-version-of-package-gdefrag/image-10/" height="520" sizes="(max-width: 1024px) 100vw, 1024px" src="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png?w=1024" srcset="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png?w=1024 1024w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png?w=150 150w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png?w=300 300w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png?w=768 768w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-1.png 1920w" style="width:631px;height:auto" width="1024"/></figure></div>
<p class="has-text-align-justify">The next, and final step, is running the function prioritize to <strong>prioritize the edges to de-fragment the landscape</strong>. The you can plot the whole results:</p>
<pre class="wp-block-code"><code>out3 <- prioritize(nodes = out1, edges = out2, method = "value")
#Plot the results:
plotgraph(nodes = out1, edges = out3, land_polyg = road_P, main = "Habitat value")</code></pre>
<p>This will <strong>create the following plot</strong>:</p>
<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img alt="" class="wp-image-2350" data-attachment-id="2350" data-comments-opened="1" data-image-caption="" data-image-description="" data-image-meta='{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0"}' data-image-title="image" data-large-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png?w=640" data-medium-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png?w=300" data-orig-file="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png" data-orig-size="1920,975" data-permalink="https://geekcologist.wordpress.com/2025/02/05/new-version-of-package-gdefrag/image-11/" height="520" sizes="(max-width: 1024px) 100vw, 1024px" src="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png?w=1024" srcset="https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png?w=1024 1024w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png?w=150 150w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png?w=300 300w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png?w=768 768w, https://geekcologist.wordpress.com/wp-content/uploads/2025/02/image-2.png 1920w" style="width:744px;height:auto" width="1024"/></figure></div>
<p><strong>That’s it! You have to check the manual for information about each function’s specific arguments.</strong></p>
<p></p>
<div id="atatags-370373-67a36c235faf2">
<script type="text/javascript">
__ATA.cmd.push(function() {
__ATA.initVideoSlot('atatags-370373-67a36c235faf2', {
sectionId: '370373',
format: 'inread'
});
});
</script>
</div><span id="wordads-inline-marker" style="display: none;"></span> <div id="atatags-26942-67a36c235fb63"></div>
<script>
__ATA.cmd.push(function() {
__ATA.initDynamicSlot({
id: 'atatags-26942-67a36c235fb63',
location: 120,
formFactor: '001',
label: {
text: 'Advertisements',
},
creative: {
reportAd: {
text: 'Report this Ad',
},
privacySettings: {
text: 'Privacy',
}
}
});
});
</script><div class="sharedaddy sd-like-enabled sd-sharing-enabled" id="jp-post-flair"><div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-icon sd-sharing"><h3 class="sd-title">Share this:</h3><div class="sd-content"><ul><li class="share-twitter"><a class="share-twitter sd-button share-icon no-text" data-shared="sharing-twitter-2339" href="https://geekcologist.wordpress.com/2025/02/05/new-version-of-package-gdefrag/?share=twitter" rel="nofollow noopener noreferrer" target="_blank" title="Click to share on Twitter"><span></span><span class="sharing-screen-reader-text">Click to share on Twitter (Opens in new window)</span></a></li><li class="share-facebook"><a class="share-facebook sd-button share-icon no-text" data-shared="sharing-facebook-2339" href="https://geekcologist.wordpress.com/2025/02/05/new-version-of-package-gdefrag/?share=facebook" rel="nofollow noopener noreferrer" target="_blank" title="Click to share on Facebook"><span></span><span class="sharing-screen-reader-text">Click to share on Facebook (Opens in new window)</span></a></li><li class="share-mastodon"><a class="share-mastodon sd-button share-icon no-text" data-shared="sharing-mastodon-2339" href="https://geekcologist.wordpress.com/2025/02/05/new-version-of-package-gdefrag/?share=mastodon" rel="nofollow noopener noreferrer" target="_blank" title="Click to share on Mastodon"><span></span><span class="sharing-screen-reader-text">Click to share on Mastodon (Opens in new window)</span></a></li><li class="share-bluesky"><a class="share-bluesky sd-button share-icon no-text" data-shared="sharing-bluesky-2339" href="https://geekcologist.wordpress.com/2025/02/05/new-version-of-package-gdefrag/?share=bluesky" rel="nofollow noopener noreferrer" target="_blank" title="Click to share on Bluesky"><span></span><span class="sharing-screen-reader-text">Click to share on Bluesky (Opens in new window)</span></a></li><li class="share-end"></li></ul></div></div></div><div class="sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded" data-name="like-post-frame-146087315-2339-67a36c23601a1" data-src="//widgets.wp.com/likes/index.html?ver=20250205#blog_id=146087315&post_id=2339&origin=geekcologist.wordpress.com&obj_id=146087315-2339-67a36c23601a1" data-title="Like or Reblog" id="like-post-wrapper-146087315-2339-67a36c23601a1"><div class="likes-widget-placeholder post-likes-widget-placeholder" style="height: 55px;"><span class="button"><span>Like</span></span> <span class="loading">Loading...</span></div><span class="sd-text-color"></span><a class="sd-link-color"></a></div>
<div class="jp-relatedposts" id="jp-relatedposts">
<h3 class="jp-relatedposts-headline"><em>Related</em></h3>
</div></div>