Skip to content

Commit

Permalink
Merge pull request #11 from ghislainv/dev
Browse files Browse the repository at this point in the history
Remove year attribute, keep only date
  • Loading branch information
ghislainv authored Mar 12, 2021
2 parents 9b0e2b5 + 66e16a6 commit 18ef11d
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 65 deletions.
Binary file modified docs/_images/notebooks_get_started_10_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions docs/_modules/pywdpa/get_wdpa.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h1>Source code for pywdpa.get_wdpa</h1><div class="highlight"><pre>
<span class="n">response</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">)</span> <span class="c1"># Equivalent to response.json()</span>

<span class="n">pas_count</span> <span class="o">=</span> <span class="n">response</span><span class="p">[</span><span class="s2">&quot;country&quot;</span><span class="p">][</span><span class="s2">&quot;pas_count&quot;</span><span class="p">]</span>
<span class="n">pages</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">pas_count</span> <span class="o">/</span> <span class="mf">50.0</span><span class="p">))))</span>
<span class="n">pages</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">pas_count</span> <span class="o">/</span> <span class="mf">50.0</span><span class="p">))))</span>

<span class="k">if</span> <span class="n">pas_count</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>

Expand All @@ -173,7 +173,6 @@ <h1>Source code for pywdpa.get_wdpa</h1><div class="highlight"><pre>
<span class="n">layer</span><span class="o">.</span><span class="n">CreateField</span><span class="p">(</span><span class="n">ogr</span><span class="o">.</span><span class="n">FieldDefn</span><span class="p">(</span><span class="s2">&quot;iucn_cat&quot;</span><span class="p">,</span> <span class="n">ogr</span><span class="o">.</span><span class="n">OFTString</span><span class="p">))</span>
<span class="n">layer</span><span class="o">.</span><span class="n">CreateField</span><span class="p">(</span><span class="n">ogr</span><span class="o">.</span><span class="n">FieldDefn</span><span class="p">(</span><span class="s2">&quot;status&quot;</span><span class="p">,</span> <span class="n">ogr</span><span class="o">.</span><span class="n">OFTString</span><span class="p">))</span>
<span class="n">layer</span><span class="o">.</span><span class="n">CreateField</span><span class="p">(</span><span class="n">ogr</span><span class="o">.</span><span class="n">FieldDefn</span><span class="p">(</span><span class="s2">&quot;date&quot;</span><span class="p">,</span> <span class="n">ogr</span><span class="o">.</span><span class="n">OFTString</span><span class="p">))</span>
<span class="n">layer</span><span class="o">.</span><span class="n">CreateField</span><span class="p">(</span><span class="n">ogr</span><span class="o">.</span><span class="n">FieldDefn</span><span class="p">(</span><span class="s2">&quot;year&quot;</span><span class="p">,</span> <span class="n">ogr</span><span class="o">.</span><span class="n">OFTString</span><span class="p">))</span>

<span class="c1"># API</span>
<span class="n">category</span> <span class="o">=</span> <span class="s2">&quot;v3/protected_areas/search/&quot;</span>
Expand Down Expand Up @@ -226,8 +225,6 @@ <h1>Source code for pywdpa.get_wdpa</h1><div class="highlight"><pre>
<span class="n">feature</span><span class="o">.</span><span class="n">SetField</span><span class="p">(</span><span class="s2">&quot;iucn_cat&quot;</span><span class="p">,</span> <span class="n">pa</span><span class="p">[</span><span class="s2">&quot;iucn_category&quot;</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
<span class="n">feature</span><span class="o">.</span><span class="n">SetField</span><span class="p">(</span><span class="s2">&quot;status&quot;</span><span class="p">,</span> <span class="n">pa</span><span class="p">[</span><span class="s2">&quot;legal_status&quot;</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
<span class="n">feature</span><span class="o">.</span><span class="n">SetField</span><span class="p">(</span><span class="s2">&quot;date&quot;</span><span class="p">,</span> <span class="n">pa</span><span class="p">[</span><span class="s2">&quot;legal_status_updated_at&quot;</span><span class="p">])</span>
<span class="n">feature</span><span class="o">.</span><span class="n">SetField</span><span class="p">(</span>
<span class="s2">&quot;year&quot;</span><span class="p">,</span> <span class="n">pa</span><span class="p">[</span><span class="s2">&quot;legal_status_updated_at&quot;</span><span class="p">][</span><span class="o">-</span><span class="mi">4</span><span class="p">:])</span>
<span class="c1"># Add feature to layer</span>
<span class="n">layer</span><span class="o">.</span><span class="n">CreateFeature</span><span class="p">(</span><span class="n">feature</span><span class="p">)</span>
<span class="c1"># Dereference the feature</span>
Expand Down
26 changes: 10 additions & 16 deletions docs/_sources/notebooks/get_started.ipynb.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h1>Changelog<a class="headerlink" href="#changelog" title="Permalink to this he
<div class="section" id="pywdpa-0-1-5">
<h2>pywdpa 0.1.5<a class="headerlink" href="#pywdpa-0-1-5" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Including more attributes (in particular legal_status and legal_status_updated)</p></li>
<li><p>Including more attributes (in particular status and date).</p></li>
</ul>
</div>
<div class="section" id="pywdpa-0-1-4">
Expand Down
10 changes: 2 additions & 8 deletions docs/notebooks/get_started.html

Large diffs are not rendered by default.

26 changes: 10 additions & 16 deletions docs/notebooks/get_started.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

26 changes: 10 additions & 16 deletions docsrc/notebooks/get_started.ipynb

Large diffs are not rendered by default.

Binary file modified docsrc/notebooks/pa_REU.dbf
Binary file not shown.
Binary file modified docsrc/notebooks/pa_REU.shp
Binary file not shown.
Binary file modified docsrc/notebooks/pa_REU.shx
Binary file not shown.
3 changes: 0 additions & 3 deletions pywdpa/get_wdpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def get_wdpa(iso3, output_dir="."):
layer.CreateField(ogr.FieldDefn("iucn_cat", ogr.OFTString))
layer.CreateField(ogr.FieldDefn("status", ogr.OFTString))
layer.CreateField(ogr.FieldDefn("date", ogr.OFTString))
layer.CreateField(ogr.FieldDefn("year", ogr.OFTString))

# API
category = "v3/protected_areas/search/"
Expand Down Expand Up @@ -126,8 +125,6 @@ def get_wdpa(iso3, output_dir="."):
feature.SetField("iucn_cat", pa["iucn_category"]["name"])
feature.SetField("status", pa["legal_status"]["name"])
feature.SetField("date", pa["legal_status_updated_at"])
feature.SetField(
"year", pa["legal_status_updated_at"][-4:])
# Add feature to layer
layer.CreateFeature(feature)
# Dereference the feature
Expand Down

0 comments on commit 18ef11d

Please sign in to comment.