Editing the DBF for a shapefile is yielding totally different results in R and QGIS,

المشرف العام

Administrator
طاقم الإدارة
I'm having kind of a peculiar issue that I'm hoping someone can shed some light on. I'm actually creating my map in R, but I'm using QGIS as a tool to check my mapping process (R newb here). So let's dig into it.

I'm trying to plot rivers in my area of interest (Tanzania), but the source shapefile (diva-gis.org) includes tons of unnecessary water lines. For the sake of reproducability, I'll be including all edited DBFs and shapefiles. Here is the original DBF file and here is the original shapefile. It looks like this.

As you can see in the DBF, many of the rivers are unknown/unnamed and listed as "UNK" which isn't very useful for me. In QGIS, I am simply able to open the attribute table, sort by name, and remove all UNK values. Alternatively, I can filter out those values through the SQL expression:

"NAM" != "UNK"Both of these yield the same results. Here is the QGIS edited DBF and here is the QGIS edited shapefile. This is what the map looks like:

Then things get quirky. Again, I'm actually creating this map in R. Using the original source data, I edit the DBF with the "foreign" package, overwrite the DBF, and then map using ggplot. I'm getting a totally different result than the one pictured above. Here's a little snippet of example code (not for the full map, but this is essentially what this portion of the map code will look like):

library(rgdal)library(foreign)library(ggplot2)#set your appropriate working directorysetwd("D:/Mapping-R/Returns-Practice")#read dbf, sql expression to remove all UNK values in NAMwater.lines
 
أعلى