Sunday, 31 March 2019

windows - QGIS not coming to foreground


I recently upgraded from QGIS 3.2 to 3.4 using the standalone installer (Windows 64 bit), and uninstalling 3.2 beforehand. When I open 3.4 it goes the background behind all my other open programs and clicking its icon on the taskbar does nothing, nor does Alt-Tab. To use QGIS I have to minimize all my other open programs.


Is this a Windows issue, a QGIS issue, or something else entirely?




ogr2ogr - Converting shapefile from Shift_JIS to UTF-8 when the usual methods fail


Long story short, I'm trying to import this ESRI shapefile of Japan into CartoDB. (Sorry, no direct link: to download, click on the orange ファイルのダウンロード button, check 同意する to agree to the T&C, then click on the green 全国市区町村界データのダウンロード button.)



Problem is, the DBF in the file is encoded as Shift_JIS, and CartoDB only likes UTF-8. I've tried the following unsuccessfully:


1) ogr2ogr


ogr2ogr --config SHAPE_ENCODING Shift_JIS japan_ver72_utf8.shp 

No-op: SJIS in, SJIS out.


ogr2ogr --config SHAPE_ENCODING UTF-8 japan_ver72_utf8 japan_ver72.shp

Makes ogr2ogr think the input is UTF-8, meaning I get garbage out.


2) QGIS


Load the shapefile into QGIS as ShiftJIS. But while the shapes load fine, QGIS dumps a whole bunch of this on load:



ERROR 1: fread(48623) failed on DBF file.

And inspecting the attribute table just shows a bunch of nulls, so there's no point trying to save as UTF-8.


3) OpenOffice Calc


Load the DBF into OpenOffice, re-export as SJIS. But OO throws an error when parsing the DBF and refuses to import the file at all.


4) iconv


Run iconv directly on the DBF:


iconv -f Shift_JIS -t UTF-8 japan_ver72_sjis.dbf >japan_ver72.dbf

This "works", in the sense that the Japanese within is correctly recoded as UTF-8, but it destroys the DBF in the process.



Ideas?



Answer



If you only need to do the job once and there is no need to go to scripting then one simple way is to convert the data with OpenJUMP.


Activate the charactes set selection from menu Customize - Options


enter image description here


Open your dataset as Shift-JIS


enter image description here


Save data back with Save as... and select UTF-8 charset


enter image description here


merge - Connect points from two SpatialPointsDataFrames in R, considering the closest distance


I have two SpatialPointsDataFrames. In SpatialPointsDataFrame one (dat1) I have three points (A, B and C). In SpatialPointsDataFrame two (dat2), I have eight points with temperature measurements. I must connect each of those eight points to the closest point from dat1 and then calculate the average temperature for each point. How can I do that in R?



library(sp)
library(tmap)

# SpatialPointsDataFrame 1
dat_orig <- read.table(text="
point lat lng
A 15.6 80.9
B 20.9 10.9
C 1.2 81.8", header=TRUE, stringsAsFactors=FALSE)


dat1 <- dat_orig
coordinates(dat1) <- ~lng+lat

# SpatialPointsDataFrame 2
dat2_orig <- read.table(text =
"temp lat lng
18 15.6 81.9
18.5 19.9 10.9
12.3 11.2 81.8
14.2 15.6 85.9

13.1 1.2 60.9
18.5 20.8 40.9
17 14.6 10.9
18.1 14.6 11.9", header=TRUE, stringsAsFactors=FALSE)

dat2 <- dat2_orig
coordinates(dat2) <- ~lng+lat

# tmap plot
tm_shape(dat1, ylim = c(-10, 35), xlim = c(-10,100)) + tm_dots(col = "red", size = 0.2) + tm_text("point") +

tm_shape(dat2) + tm_dots(size = 0.1)

Answer



Use the FNN package:


> library(FNN)

this computes the first-nearest neighbours from dat1 for each of dat2:


> nn1 = get.knnx(coordinates(dat1), coordinates(dat2), 1)

The index into the three elements of dat1 for the 8 rows of dat2 is:


> ii = nn1$nn.index[,1]

> ii
[1] 1 2 1 1 3 2 2 2

(You can also get the distance out from nn1$nn.dist)


So we can then average the properties of dat2 grouped by that index with tapply:


> tapply(dat2$temp, list(ii), mean)
1 2 3
14.83333 18.02500 13.10000

python - TKinter to provide variables


I've been looking for a way to enter a unique field name into an attribute table for up to 40 feature classes. I need the field names to be meaningful, not just 'field1', 'field2' etc. For example, if the feature class represents wetlands I would like a field called 'Wetland'.


I thought the easiest way of doing this would be to use TKinter. I can print the feature class name and then dynamically enter a field name with the TKinter data entry msgbox. Then keep looping through the feature classes until they all have a field with a unique name.


I've found some examples but am unsure about how to use data entry text as a variable in Python. If anyone out there had an example script or can make suggestions on this script I'd appreciate it:


import arcpy
from arcpy import env
from Tkinter import *

# Environment Workspace
env.workspace = r'G:\TEST\Python_Test\Test.gdb'


def receive():
text = E1.get()
print (text)
top = Tk()
L1 = Label(top, text="User Name")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)
b = Button(top, text="OK", width=10, command=receive)

b.pack()
top.mainloop()

Answer



I managed to figure this out... My code now iterates through feature classes, requests a field name, calculates fields, deletes unwanted fields. And then joins the left over fields to each other with a spatial join. I was stuck on adding the interactive tkinter dialog box in the first loop, and the delete field text at the end of the first loop. I still have some to do on this, but thought I'd post the answers to my original question. Thought I'd put my code up for others:


import Tkinter
import tkSimpleDialog
import arcpy
from arcpy import env

env.workspace = r'G:\TEST\Python_Test\Test.gdb\env'


fcList = arcpy.ListFeatureClasses()

for fc in fcList:
print fc
root = Tkinter.Tk()
var = tkSimpleDialog.askstring("Field Name", "Enter Field Name")
print var

arcpy.AddField_management(fc, var, "TEXT", "", "", "50", "", "NULLABLE", "REQUIRED", "")

print "Adding field name " + var + " to " + fc
arcpy.CalculateField_management(fc, var, "\"Y\"", "PYTHON", "")
print "Calculating field " + var + " to " + fc

keep = ['OBJECTID', 'Shape', 'Tower', var, 'Shape_Area', 'Shape_Length']

discard = []
for field in [f.name for f in arcpy.ListFields(fc)if f.type <> 'OBJECTID']:
if field not in keep:
discard.append(field)

arcpy.DeleteField_management(fc, discard)
print "Deleted all fields except those specified"

# Input variables for spatial join
Buffer1 = r'G:\Test\Python_Test\Test.gdb\Buffer1'
Buffer2 = r'G:\Test\Python_Test\Test.gdb\Buffer2'

sjList = arcpy.ListFeatureClasses()

# For loop for spatial join process


for sj in sjList:

# Spatial join between buffered points and feature
arcpy.SpatialJoin_analysis(Buffer1, sj, Buffer2, "JOIN_ONE_TO_ONE", "KEEP_ALL")
print "Completed spatial join " + sj

# Delete Buffer1 containing no joined features
arcpy.Delete_management(Buffer1, "FeatureClass")
print "deleted Buffer1 " + sj


# Copies Buffer2 containing joined features and outputs as Buffer1
arcpy.Copy_management(Buffer2, Buffer1, "")
print "Copied Buffer2 to Buffer1 " + sj

# Deletes Buffer2 to allow script to create Buffer2 in next iteration
arcpy.Delete_management(Buffer2, "FeatureClass")
print "Deleted Buffer2 " + sj

arcobjects - Error opening feature class from SDE (which can be opened in another application)


We're using ArcGIS 10.1 with ArcSDE 9.3.1 on Oracle 10g.


I've got two layers that cannot be opened or modified with ArcCatalog or ArcMap (but they show up in the list. Everything worked just fine until a few days ago when I added some columns from a third party software using SQL. As if this wasn't foolish enough (as it seems on Google) I also had an MXD open with these layers in it.


Now I can't open or use them in any ArcEnviroment of any kind (also tried Topocad and FME, and on different computers, one of them has ArcGIS 9.3.1... No go). Mostly I only get "Error opening feature class". Sometimes when I try to open the properties of the layers I get "Failed to edit the selected object(s). The workspace is not connected. Table attachments not supported in this release of the Geodatabase.". I've also gotten "Arcobjects error -2147216117 - Network I/O error".


The third party application however, can open and use them just fine, although it's reading from a view consisting of the data table + geometry table (the "F****"-tables) for each respective layer. With this in mind I've checked the database. Both the data tables and geometry tables exist with no errors and the connection between them is registered. I read somewhere on Google that the SDE.COLUMN_REGISTRY table could get out of sync when adding columns via SQL. So I checked it, but it's in sync. I also checked some metadata tables but couldn't see anything there (I don't really know what I'm looking for in there though).


My best guess is that the problem lies somewhere "between" ArcGIS and the database, since the tables obviously exists and is working in the third party application. There's no network error either since the rest of the database layers and tables can be used just fine. I'm guessing the problem lies in some kind of registry, metadata tables or cache, but I'm getting all out of ideas.


edit: I forgot to mention that the tables are not versioned, and we tried a server reboot.


Anyone have any ideas?




Saturday, 30 March 2019

javascript - List all columns of a dataset?



Using CARTO VL.


Having a dataset, is there a way to fetch all columns this dataset has before I create the viz object so I can programmatically decide which variables to add to the viz?


Something like:


const source = new carto.source.Dataset('my-dataset');
const columns = source.getColumns();


Slider for non time attributes in QGIS



How to filter data on attributes with a slider?


By example, i would like to filter weights (CHARGE in my layer) attribute for polygons without to change the filter formula.


enter image description here


The feature is available for time window. I don't know other solutions for non date/time type attributes.


How can i do?




qgis - How can i delete multiple nodes, for a polygon, with Quantum GIS?


I know how to select a single node and delete it. I can also click-drag to select MULTIPLE nodes. But if i click delete, only one node (from the higlighted list) is removed.


Can I delete all the highlighted nodes?


UPDATE:


Here's a quick YouTube clip, showing how it's not working. U can see that when I select 2 or 3 nodes, only ONE is deleted.



Answer



That was a bug #5657 that was fixed already in master.


arcgis 10.1 - Using ArcPy FieldMappings for Spatial Join?


I'm trying to create a python script tool to use within ArcMap 10.1. I created a Model and exported it as a python script and added custom field mappings for the first Spatial Join by reading through others' example scripts, however, the resulting fields when the script is run don't join using the "; " delimiter, and the output fields are the same as the input. I currently run the script as a python tool in ArcMap 10.1.


I'm stumped at this point even after reading all articles from ESRI on the FieldMappings object and its methods. The script is as follows if anyone would like to take a look:


import arcpy

# Script arguments

Waterbodies_UTM13_20130228 = arcpy.GetParameterAsText(0)

MT_ESA_20131023 = arcpy.GetParameterAsText(1)

wbdhu8_a_mt = arcpy.GetParameterAsText(2)

Montana_Soils__2_ = arcpy.GetParameterAsText(3)

WB_HUC_Intersect_ESA_UTM13_M1 = arcpy.GetParameterAsText(4)



# Local variables:
Waterbodies_UTM13_20130228__2_ = Waterbodies_UTM13_20130228
Waterbodies_or_Wetlands_on_ESA = Waterbodies_UTM13_20130228__2_
WL_WB_Joined_with_HUC_Basins_Data = Waterbodies_or_Wetlands_on_ESA
Biological_ESA_MT_Intersect = WL_WB_Joined_with_HUC_Basins_Data
Biological_ESA_MT_Intersect_ = Biological_ESA_MT_Intersect


# Process: Select Layer By Attribute: Selects all USACE = "Yes" features

arcpy.SelectLayerByAttribute_management(Waterbodies_UTM13_20130228, "NEW_SELECTION", "\"USACE\" = 'Yes'")

# Process: Select Layer By Location: Selects all features from the USACE = "Yes" features that intersect the ESA
arcpy.SelectLayerByLocation_management(Waterbodies_UTM13_20130228__2_, "INTERSECT", MT_ESA_20131023, "", "SUBSET_SELECTION")


# FieldMappings for Spatial Join process: Create a new "fieldmappings" and add the join features' attribute table
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(Waterbodies_UTM13_20130228)
fieldmappings.addTable(wbdhu8_a_mt)


# FieldMappings for Spatial Join process: Get the fields maps for the fields: REGION, SUBREGION, BASIN, and SUBBASIN
RegionFieldIndex = fieldmappings.findFieldMapIndex("REGION")
fieldmap1 = fieldmappings.getFieldMap(RegionFieldIndex)

SubRegionFieldIndex = fieldmappings.findFieldMapIndex("SUBREGION")
fieldmap2 = fieldmappings.getFieldMap(SubRegionFieldIndex)

BasinFieldIndex = fieldmappings.findFieldMapIndex("BASIN")
fieldmap3 = fieldmappings.getFieldMap(BasinFieldIndex)


SubBasinFieldIndex = fieldmappings.findFieldMapIndex("SUBBASIN")
fieldmap4 = fieldmappings.getFieldMap(SubBasinFieldIndex)

# FieldMappings for Spatial Join process: Set output fields and allowed field length to max (255)
field1 = fieldmap1.outputField
field2 = fieldmap2.outputField
field3 = fieldmap3.outputField
field4 = fieldmap4.outputField


field1.length = "255"
field2.length = "255"
field3.length = "255"
field4.length = "255"

fieldmap1.outputField = field1
fieldmap2.outputField = field2
fieldmap3.outputField = field3
fieldmap4.outputField = field4


# FieldMappings for Spatial Join process: Set the merge rule to join using the "; " delimiter and replace the old fieldmaps for each of the fields in the mappings object with updated one
fieldmap1.mergeRule = "Join"
fieldmap1.joinDelimiter = "; "
fieldmappings.replaceFieldMap(RegionFieldIndex, fieldmap1)

fieldmap2.mergeRule = "Join"
fieldmap2.joinDelimiter = "; "
fieldmappings.replaceFieldMap(SubRegionFieldIndex, fieldmap2)

fieldmap3.mergeRule = "Join"

fieldmap3.joinDelimiter = "; "
fieldmappings.replaceFieldMap(BasinFieldIndex, fieldmap3)

fieldmap4.mergeRule = "Join"
fieldmap4.joinDelimiter = "; "
fieldmappings.replaceFieldMap(SubBasinFieldIndex, fieldmap4)


# Process: Spatial Join: Spatially joins the HUC Basins data to the target WL or WB features (attributes are not "joined"; if a WB or WL falls on more than one basin,
# fieldmappings will concatenate attributes from select fields using "; " as a delimiter

arcpy.SpatialJoin_analysis(Waterbodies_or_Wetlands_on_ESA, wbdhu8_a_mt, WL_WB_Joined_with_HUC_Basins_Data, "JOIN_ONE_TO_ONE", "KEEP_ALL", fieldmappings, "INTERSECT")

# Process: Intersect: Intersects the temp output file from Spatial Join containing the joined WB or WL with the ESA, to create WL or WB pieces within the ESA
arcpy.Intersect_analysis([WL_WB_Joined_with_HUC_Basins_Data, MT_ESA_20131023], Biological_ESA_MT_Intersect, "ALL", "", "INPUT")

# Process: Multipart To Singlepart: Explodes all WL or WB pieces into singlepart features
arcpy.MultipartToSinglepart_management(Biological_ESA_MT_Intersect, Biological_ESA_MT_Intersect_)

# Process: Spatial Join (2): Spatially joins the exploded WL or WB features containing the HUC basins data with the Soils Data; attributes ARE "joined" and
# use "; " to deliminate all attributes from features that intersect the WL or WB features

arcpy.SpatialJoin_analysis(Biological_ESA_MT_Intersect_, Montana_Soils__2_, WB_HUC_Intersect_ESA_UTM13_M1, "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT", "", "")

Screenshot of the error window in ArcMap: error message


Line 95:


arcpy.SpatialJoin_analysis(Waterbodies_or_Wetlands_on_ESA, wbdhu8_a_mt, WL_WB_Joined_with_HUC_Basins_Data, "JOIN_ONE_TO_ONE", "KEEP_ALL", fieldmappings, "INTERSECT")


Reducing Land Cover Data Sets in Earth Engine


I am trying to use earth engine to reduce the USGS land cover dataset and calculate the frequency of specific land cover types in several regions. The output that I am getting creates a single dictionary with a list of land cover types and values for each county (region).


I am curious if I can break this dictionary up to allow a table to be exported to google drive with each land cover type having a unique column?


Here is my code:


// Load a FeatureCollection of Maine Counties.

var Counties = ee.FeatureCollection('ft:1S4EB6319wWW2sWQDPhDvmSBIVrD3iEmCLYB7nMM').filter(ee.Filter.eq('StateName', 'Maine'));

//Imports NLCD Land Cover Data
var LandCover2011 = ee.Image('USGS/NLCD/NLCD2011')

// Clip the image to the polygon geometry
var LandCover2011 = LandCover2011.clip(Counties);

// Extract the landcover band
var landcover = LandCover2011.select('landcover');



// Print out the frequency of landcover occurrence for each county
var frequency = landcover.reduceRegions({
collection: Counties,
reducer:ee.Reducer.frequencyHistogram(),
scale:30
});

//Prints Feature collection

print(frequency);

//Exports table to drive
//Export.table.toDrive(frequency, "MaineLandCoverData");

Answer



You can get the "histogram" property (resulting from the reducer) as a Dictionary which can be used to set the landcover:frequency pairs as new properties for a county feature. Then just map that function over all counties in the FeatureCollection.


// Print out the frequency of landcover occurrence for each county
//...

// Optional for debugging: Drop other properties and geometry > simpler looking csv.

frequency = frequency.select(['histogram'], null, false)

var frequency = frequency.map(function(feature){
var dict = ee.Dictionary(feature.toDictionary().get('histogram'))
feature = feature.set(dict)
return feature
})
print('per class landcover frequency properties', frequency)

//Exports table to drive

Export.table.toDrive(frequency, "MaineLandCoverData");

Integrate GeoJSON file with openlayers.protocol.http


I've got a problem with (the title says it) integrating a geojson file in my openlayers map. I have to use the openlayers.protocol.http way. I examined lots of examples on the web (and on stackexchange) but I cannot figure out what the problem with my exact code is. it shows the layer in the layerswitcher, but it doesn't show the features.


I hope someone can find the error. Here's my code (relating geojson):


WebMapping - Übung 12












Ihr Browser unterstützt keine Inlineframes



Wikipedia-Integration in OpenLayers








Answer



Well, here is my working example. First of all, your code have some errors. Read carefully this to discover what was changed, because I don't have time to comment and explain in details.


























And the file with GeoJSON:



{"type":"FeatureCollection",
"features":[
{"type":"Feature",
"properties":{
"name":"TRON-02",
"color":"green",
"size":15
},
"geometry":{
"type":"Point",

"coordinates":[8.692, 49.412]
}
}
]
}

Feel free to ask anything you don't understand. 1) Format your HTML correctly. 2) Your map don't call the correct DIV tag to render. 3) I put a projection in the vector. 4) CHanged the coordinates to my country (eheh) so you will know where to go the next Football World Cup.


pyqgis - QGIS 2.14 Python sub-menus


I'm trying to add sub-menu items to a menu that linked to a toolbar icon. It's probably best to show what result I'm getting currently, then reference the code:


enter image description here


The code is coming from a plugin class:



class SandBox2:


def __init__(self, iface):
self.iface = iface
self.plugin_dir = os.path.dirname(os.path.realpath(__file__))
self.actions = []

def initGui(self):
self.toolbar = self.iface.addToolBar("Sandbox2")
self.toolbar.setObjectName("Sandbox2")


self.SetupSubMenu = QAction((QIcon("C:/Users/Rudy/.qgis2/python/plugins/arcLensStandard/icons/new.png")), "Sub-Item 1-1",self.iface.mainWindow())
self.submenu_11 = QMenu(self.iface.mainWindow())
self.submenu_11.addAction(self.SetupSubMenu)
self.SetupSubMenu.triggered.connect(self.runMsg1)

self.SetupMainMenuItem = QAction((QIcon("C:/Users/Rudy/.qgis2/python/plugins/arcLensStandard/icons/item_one.png")), "First Menu Item", self.iface.mainWindow())
self.Menu1 = QMenu(self.iface.mainWindow())
self.Menu1.addAction(self.SetupMainMenuItem)
self.Menu1.addMenu(self.submenu_11)


self.toolButton = QToolButton()
self.toolButton.setIcon(QIcon("C:/Users/Rudy/.qgis2/python/plugins/arcLensStandard/icons/adddata.png"))
self.toolButton.setMenu(self.Menu1)
self.toolButton.setPopupMode(QToolButton.InstantPopup)
self.toolbar.addWidget(self.toolButton)

def runMsg1(self):
QMessageBox.information(self.iface.mainWindow(), "Message",
"Sub-Item 1-1 Message", QMessageBox.Ok)


What I want to see is the right-facing caret symbol on the same line as the "First Menu Item" string, instead of appearing on a blank line after the string. The statement that's adding the sub-menu is:


self.Menu1.addMenu(self.submenu_11)

and that's where the blank line gets inserted (apparently).



Answer



You can assign a name to Menu1 (e.g. first_menu) and then call this when adding your action for your submenu:


def initGui(self):
self.toolbar = self.iface.addToolBar("Sandbox2")
self.toolbar.setObjectName("Sandbox2")


self.SetupSubMenu = QAction((QIcon("C:/Users/Rudy/.qgis2/python/plugins/arcLensStandard/icons/new.png")), "Sub-Item 1-1",self.iface.mainWindow())
self.SetupSubMenu.triggered.connect(self.runMsg1)

self.Menu1 = QMenu(self.iface.mainWindow())
# Here we assign the name for the first menu
first_menu = self.Menu1.addMenu(QIcon("C:/Users/Rudy/.qgis2/python/plugins/arcLensStandard/icons/item_one.png"), "First Menu Item")
# Call first_menu to add the action for the submenu
first_menu.addAction(self.SetupSubMenu)

self.toolButton = QToolButton()

self.toolButton.setIcon(QIcon("C:/Users/Rudy/.qgis2/python/plugins/arcLensStandard/icons/adddata.png"))
self.toolButton.setMenu(self.Menu1)
self.toolButton.setPopupMode(QToolButton.InstantPopup)
self.toolbar.addWidget(self.toolButton)

Result


arcgis desktop - Sequential IDs with field calculator: Pad a prefixed field to specific length


I have an ID field that is a text datatype. The IDs in the field have a prefix, and are padded with zeros to always be a specific length. Examples:



  • INSP000098

  • INSP000099

  • INSP000100

  • INSP000101



I would like to use the Field Calculator to generate sequential IDs for new records (records are batch loaded from various sources by the thousands).


I have a python script that almost does this:


Modified from: Create sequential numbers in a field using Python in the Field Calculator


prefix = "INSP0000"
lastnumber=97

rec=0
def autoIncrement():
global rec
pStart = 1

pInterval = 1
if (rec == 0):
rec = 1 + lastnumber
else:
rec += pInterval
return prefix+str(rec)



autoIncrement()


Steps:



  1. Manually enter the prefix (with zeros for padding)

  2. Manually enter the last number in the existing IDs

  3. Run the script


Result:


Unfortunately, the tool isn't smart enough to dynamically adjust for the difference in the number of digits between numbers (99 to 100, etc.):



  • INSP000098


  • INSP000099

  • INSP0000100 << Problem: too many zeros/digits

  • INSP0000101


How can I use the field calculator to generate sequential, prefixed IDs that are padded with zeros to a specific length?


I'm not married to Python; VBScript would be an acceptable alternative.



Answer



rec=97
def withPads():
global rec

rec+=1
return 'INSP%s' %str(rec).zfill(6)
#------------
withPads()

OUTPUT:


enter image description here


arcgis desktop - Exporting a timeslice from a Netcdf-Rasterlayer as tif-rasterlayer


In ArcGIS Desktop 10.4 (advanced licence) I downloaded a NetCDF-File from here: http://eca.knmi.nl/download/ensembles/downloadchunks.php (the 0.25 grid with the years 1995-2016). It consists of temperature-data over time (in days).


I read it into ArcGIS as a NetCDF-Rasterlayer, and now I'm trying to export data of a single time-slice as a tif-rasterlayer. I did not get the hang on Mosaic Datasets, so my plan is to make a spatial analysis on the exported tif-rasterlayer, relating it to landuse (also in a tif-rasterlayer), and later aggregating it to NUTS3-Level). If I keep track what happens to which rasters I can later export other time-slices as tables and relate the spatial analysis to them.


The export-function (Data->Export) works in principle, but the raster looses it's attribute table, and without that I can't keep track which cell relates to which.


Does anyone have a suggestion on how to get that working?




coordinate system - Quick way to determine if facing a given lat/lon pair with a heading


I'm looking for a fast way, preferably without trigonometric operations (just multiply, divide, add, sqrt and subtract) to determine if a point is visible. E.g. say I am facing 0 degrees N, I am at 51.40,-1.08, the camera has a HFOV of 30 degrees and the point is at 51.20,-1.085 it should return TRUE, because the point would be facing me and is within the 30 degree FOV.


It's required that it returns TRUE (false positive) instead of FALSE given edge cases, otherwise points may be hidden when they are actually visible. Currently I have my augmented reality project using atan2 to calculate the actual angle but if I can shave calculations off from points which are definitely not visible every little bit helps. I only need it to be accurate over distances of less than 2 km.



Here's my code to calculate horizontal and vertical position. It's only accurate over <5km distances but accuracy isn't critical anyway as those waypoints aren't drawn. This project is open source, so it's okay for me to post a lot of code.


res->est_dist = hypot2(p_viewer->p.lat - p_subj->lat, p_viewer->p.lon - p_subj->lon) * 2000.0f;
// Save precious cycles if outside of visible world.
if(res->est_dist > cliph)
goto quick_exit;
// Compute the horizontal and vertical angle to the point.
res->h_angle = angle_dist_deg(RAD2DEG(atan2(p_viewer->p.lon - p_subj->lon, p_viewer->p.lat - p_subj->lat)), p_viewer->yaw);
res->v_angle = RAD2DEG(atan2(p_viewer->p.alt - p_subj->alt, res->est_dist)); // constant scale factor: needs to be adjusted
// Normalize the results to fit in the field of view of the camera.
res->h_angle += p_viewer->hfov / 2;

res->v_angle += p_viewer->vfov / 2;
// Compute projected X and Y position.
res->pos.x = (res->h_angle / p_viewer->hfov) * p_viewer->width;
res->pos.y = (res->v_angle / p_viewer->vfov) * p_viewer->height;

See that call to atan2 for the h_angle? If I could eliminate it by saying "this point is definitely not visible" it would be nice.




Friday, 29 March 2019

Calculate Acres in Territory using ArcGIS Online


I have a map of counties with each county have assigned a corn acre attribute number. I also have a territory layer that covers multiple counties. I am curious if there is a way to calculate the amount of acres to the territory based on summing the area the territory covers in ArcGis Online.



For Example: County A has 10,000 acres but territory covers 50% of the area of the county then the territory only sums 5,000 acres?


enter image description here




pyqgis - How to run the graphic modeler from the python console in QGIS?



How can I run the graphic modeler from the python console in QGIS?




arcgis desktop - Getting "real time" occurence count of values in attribute table for displaying purposes


I'm working with ArcMap 10.2 on a layer of points that I have to move. I'm using the editor to move them. What I also need is to display these points based on how many are sharing the same coordinates X and Y, because that's how I find those I need to move ( I give priority to those points which share coordinates with many other points, for reasons you don't need to be bothered with). Getting a Summary Table from the concatenated X & Y and joining the count back to my points layer is the "standard" way to go, but I need to get a "real time" count of occurence of each value and I cannot extract each time the Summary Table and make the join. I searched for and tried with some python coding in the field calculator but didn't find anything working. Ideas?




Thursday, 28 March 2019

gdal - Using dictionary of file names and DD coordinates to create points in shapefile using shapely?


I'm working on a Python script that strips the GPS info from images and uses that info to create a shapefile from that info. Right now I have all the file names as keys to tuples of decimal degrees coordinates. This dictionary prints out like this:


{'IMG_2840.jpg': (39.08861111111111, 114.80472222222222), 'IMG_2823.jpg': (38.61611111111111, 119.88777777777777), 'IMG_2912.jpg': (41.97861111111111, 106.25500000000001), 'IMG_2859.jpg': (39.742777777777775, 112.19694444444444), 'IMG_2813.jpg': (39.200833333333335, 119.79416666666665), 'IMG_2790.jpg': (41.82111111111111, 121.72472222222221), 'IMG_2753.jpg': (41.72027777777778, 124.32249999999999), 'IMG_2916.jpg': (41.01388888888889, 105.97611111111111), 'IMG_2750.jpg': (42.50833333333333, 125.72888888888889)}

How would I take this dictionary and turn it into a shapefile so that the names of the files are the names of the points?


I would prefer an open source way such as shapely or ogr/gdal.


Here's the code that generated this list. It does not really deal with spatial data at all.


filelist = os.listdir(Path)

for f in filelist:
if f.endswith(".jpg"):
with open(Path + "/" + f, 'r') as I:
print(I)
img = Image.open(Path + "/" + f)
exif = {ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS}
print(exif)
meta = exif['GPSInfo'][2]
meta = [x[0] for x in meta]
d = meta[0]

m = meta[1]
s = meta[2]
NCDict[os.path.basename(I.name)] = dms_to_dd(d=d,m=m,s=s)
# Ncoords = {I:dms_to_dd(d=d, m=m, s=s)}
# print(Ncoords)
meta2 = exif['GPSInfo'][4]
meta2 = [b[0] for b in meta2]
d = meta2[0]
m = meta2[1]
s = meta2[2]

WCDict[os.path.basename(I.name)] = dms_to_dd(d=d,m=m,s=s)
print NCDict
print WCDict

# writing xy coords to new file
corddict=[NCDict,WCDict]
finalCoord = {}
for k in NCDict.iterkeys():
finalCoord[k] = tuple(finalCoord[k] for finalCoord in corddict)
print(finalCoord)


Answer



You don't need ArcPy here, simply use the geospatial pure Python modules as GeoPandas, Fiona, Shapely, pyshp (shapefile) or osgeo.ogr


# the resulting dictionary
dicto = {'IMG_2840.jpg': (39.08861111111111, 114.80472222222222), 'IMG_2823.jpg': (38.61611111111111, 119.88777777777777), 'IMG_2912.jpg': (41.97861111111111, 106.25500000000001), 'IMG_2859.jpg': (39.742777777777775, 112.19694444444444), 'IMG_2813.jpg': (39.200833333333335, 119.79416666666665), 'IMG_2790.jpg': (41.82111111111111, 121.72472222222221), 'IMG_2753.jpg': (41.72027777777778, 124.32249999999999), 'IMG_2916.jpg': (41.01388888888889, 105.97611111111111), 'IMG_2750.jpg': (42.50833333333333, 125.72888888888889)}

With GeoPandas


# convert to a GeoDataFrame
import geopandas as gpd
result = gpd.GeoDataFrame.from_dict(dicto, orient='index').reset_index()
# rename the columns

result.columns = ['name','x','y']
print(result.head(3))
name x y
0 IMG_2840.jpg 39.088611 114.804722
1 IMG_2823.jpg 38.616111 119.887778
2 IMG_2912.jpg 41.978611 106.255000
# create a shapely geometry column
from shapely.geometry import Point
result['geometry'] = result.apply(lambda row: Point(row.x, row.y), axis=1)
# print first row as control

print(result.head(1))
name x y geometry
0 IMG_2840.jpg 39.088611 114.804722 POINT (39.08861111111111 114.8047222222222)
result.crs = "4326"
# save resulting shapefile
result.to_file("result.shp")

With Fiona:


import fiona
from shapely.geometry import mapping

from fiona.crs import from_epsg
# define the schema of the resulting shapefile
schema={'geometry': 'Point', 'properties': {'name':'str:10'}}
# create and save the resulting shapefile
with fiona.open('result2.shp', 'w',crs=from_epsg(4326),driver='ESRI Shapefile', schema=schema) as output:
for key, value in dicto.items():
point = Point(value[0],value[1])
prop = prop = {'name':key}
output.write({'geometry':mapping(point),'properties': prop})


With pyshp (without shapely)


import shapefile
w = shapefile.Writer(shapefile.POINT)
w.field('name', 'C')
for key, value in dicto.items():
w.record(key)
w.point(value[0],value[1])
w.save("result3.shp")

enter image description here



arcgis desktop - Average of raster elevation based on polygon boundaries


I am attempting to extract and calculate the average height of buildings using LiDAR converted to raster elevation data. I've created a DSM to cover the entire area and I am trying to extract just the buildings out, I need the average height based upon the DSM elevation pixels. How do I calculate this?


I've attempted clipping these images out according to the polygons (which created thousands of individual rasters) but still I am unsure how to get the average within the bounds of the footprint.


Building with footprint outline and 10cm pixels




Using GDAL polygonize from Python?


I have been using gdal from the command line to convert an asc file to a GeoJSON output. I can do this successfully:


gdal_polygonize.py input.asc -f "GeoJSON" output.json


Now I wish to use Python and follow this process for a range of files.


import gdal
import glob
for file in glob.glob("dir/*.asc"):

new_name = file[:-4] + ".json"
gdal.Polygonize(file, "-f", "GeoJSON", new_name)

Hpwever, for exactly the same file I get the following error TypeError: in method 'Polygonize', argument 1 of type 'GDALRasterBandShadow *'


Why does the command line version work and the python version not?



Answer



You are confusing the use of the gdal_polygonize command line utility with the python function gdal.Polygonize().


As you mentioned, you've managed to use the command line utility successfully; however, the Python function works differently and expects different arguments than those specified in the utility. The first argument should be a GDAL Band object, not a string, so this is why you get your error.


To get the Band object you need to open the input file using gdal.Open() and use the GetRasterBand() method to get your intended band. Additionally, you need to create an output layer in which the resulting polygons will be created.


The Python GDAL/OGR Cookbook has a good example on how to use this function. The required parameters are explained in a bit more detail here.





Alternative


Following on from your comment, if you would prefer to keep using the command line utility, one solution is to call it from within a Python script using the subprocess module i.e.


import subprocess

script = 'PATH_TO_GDAL_POLYGONIZE'
for in_file in glob.glob("dir/*.asc"):
out_file = in_file[:-4] + ".json"
subprocess.call(["python",script,in_file,'-f','GeoJSON',out_file])


This loops through the files and updates the input/output paths.


This way you get the result that you are use to getting from the utility, but the ability to loop through your files. If you do plan on going this way, the subprocess documention will be useful.


pyqgis - PyCharm 2019 is not working with QGIS anymore


Since the update to PyCharm 2019 I am unable to load the QGIS Python modules. I can not use auto completion either. I already deleted the cache (by invalidating the cache in PyCharm and also by deleting the "system" folder in the user settings directory), nothing seems to work.


When starting the Python console inside of PyCharm and typing "import qgis.core", I get the following error:


Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\OSGEO4~1\apps\qgis-ltr\python\qgis\core\__init__.py", line 27, in
from qgis._core import *
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import

module = self._system_import(name, *args, **kwargs)
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

Something seems to be broken, in PyCharm 2018.3 everything was ok. The sys.path environments and interpreter settings seem to be correct:


['C:\\Program Files\\JetBrains\\PyCharm Community Edition '
'2018.2.2\\helpers\\pydev',
'C:\\OSGEO4~1\\apps\\qgis-ltr\\python',
'C:\\OSGEO4~1\\apps\\qgis-ltr\\python\\plugins',
'C:\\Program Files\\JetBrains\\PyCharm Community Edition '
'2018.2.2\\helpers\\third_party\\thriftpy',

'C:\\Program Files\\JetBrains\\PyCharm Community Edition '
'2018.2.2\\helpers\\pydev',
'C:\\OSGeo4W64\\apps\\Python37\\python37.zip',
'C:\\OSGEO4~1\\apps\\Python37\\DLLs',
'C:\\OSGEO4~1\\apps\\Python37\\lib',
'C:\\OSGeo4W64\\apps\\Python37',
'C:\\OSGEO4~1\\apps\\Python37',
'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages',
'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages\\win32',
'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages\\win32\\lib',

'C:\\OSGEO4~1\\apps\\Python37\\lib\\site-packages\\Pythonwin']

Has anyone updated PyCharm to 2019 and can confirm this? I also reinstalled the whole QGIS installation, but nothing seems to work.


It looks like the DLLs containing the stubs are incompatible now?


My bat for starting PyCharm looks like this:


@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-7.4.2\etc\env.bat
@echo off

path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-7.4.2\lib
path %PATH%;%OSGEO4W_ROOT%\apps\Qt5\bin
path %PATH%;%OSGEO4W_ROOT%\apps\Python37\Scripts
path %PATH%;C:\Program Files\Docker\Docker\Resources\bin
path %PATH%;C:\Program Files\7-Zip

set QT_PLUGIN_PATH=C:\OSGeo4W64\apps\Qt5\plugins

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis-ltr\python

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis-ltr\python\plugins
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37

start "PyCharm aware of Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.2\bin\pycharm64.exe" %*


qgis - Qgis2web fails to display points with SVG markers


I made a map and put some points on it and I symbolized some points as svg markers from QGis library.Now, when I wanted to display or export the map with the gis2web plugin (openlayers option checked), I couldn't see the points. When I symbolized them as simple markers I saw them on the published map. What's happened? I've used QGIS 2.6.1 and qgis2web 0.35.




Wednesday, 27 March 2019

qgis - Opening .shp file under Add Vector Layer


When I try to open streets.ship file from the exercise data file downloaded for working in the Quantum GIS Training Manual, I get an error message: Invalid Data Source C:/Users/new user/Documents/streets.ship is not a valid or recognized data source. What am I doing wrong?





Using HERE background maps in QGIS


The OpenLayers plugin for QGIS allows one to add background maps from various sources to the data frame. These sources include OSM, Google, Bing, MapQuest, and Apple. However, Nokia's HERE Maps, is not among them.


Does anyone know how to add this, or is there another option available to use HERE Maps as a background in QGIS?


As far as I know, there is no straightforward way to add HERE Maps as a background in ArcMap, but it is possible in FME Data Inspector, as long as you have a HERE Developer account.



Answer



I posted an answer about how to add a BaseLayer as Rasterlayer some weeks ago: High resolution, printable alternative to OpenLayers plugin for QGIS? . What I described there can also be used for HERE-Layers.




As user Mapperz already mentioned you need an app_id and app_code to use Here-Tiles. You will get these credentials here: https://developer.here.com/rest-apis/documentation/enterprise-map-tile/common/credentials.html . You should also have a look at the terms of use if there are legal restrictions about how the tiles can be used or requested.





To load the HERE-Baselayer in QGIS you can use the GDAL minidriver.


Here's the XML-Code:




http://1.base.maps.api.here.com/maptile/2.1/maptile/newest/normal.day/${z}/${x}/${y}/256/png8?app_id=YOURAPPID&app_code=YOURAPPCODE


-20037508.34
20037508.34

20037508.34
-20037508.34

20
1
1
top

EPSG:3857
256

256
3



Just save this as a xml-file (Replace the placeholder YOURAPPID and YOURAPPCODE) and open it with the "add Raster Layer" button:




enter image description here


This works for a bunch of different layertypes, just have a look at this for further information: https://developer.here.com/rest-apis/documentation/enterprise-map-tile/topics/examples.html


Here some screenshots:



"Here Normal Day":


enter image description here


"Here Traffic" with the up to date traffic information: enter image description here




EDIT 1: Added another Option: Tile-Layer-Plugin:


If you use the TileLayer-Plugin you can even store your userdefined tile-layer-settings:


Install the plugin: enter image description here


You will need to use a textfile where you store your userdefined Layers. lets call it "tile_layer_plugin.tsv".


The content can look like this:


#title  credit  serviceUrl  yOriginTop  zmin    zmax    xmin    ymin    xmax    ymax

here Normal Day © Here Nokia http://1.base.maps.api.here.com/maptile/2.1/maptile/newest/normal.day/{z}/{x}/{y}/256/png8?app_id=YOUR_APP_ID&app_code=YOUR_APP_CODE 1 0 20
here Traffic © Here Nokia http://1.traffic.maps.api.here.com/maptile/2.1/traffictile/newest/normal.day/{z}/{x}/{y}/256/png8?app_id=YOUR_APP_ID&app_code=YOUR_APP_CODE 1 0 20
here Aerial Terrain © Here Nokia http://1.aerial.maps.api.here.com/maptile/2.1/maptile/newest/terrain.day/{z}/{x}/{y}/256/png8?app_id=YOUR_APP_ID&app_code=YOUR_APP_CODE 1 0 20
here Aerial Satellite © Here Nokia http://2.aerial.maps.cit.api.here.com/maptile/2.1/maptile/newest/satellite.day/{z}/{x}/{y}/256/png8?app_id=YOUR_APP_ID&app_code=YOUR_APP_CODE 1 0 20
here Aerial Hybrid © Here Nokia http://2.aerial.maps.cit.api.here.com/maptile/2.1/maptile/newest/hybrid.day/{z}/{x}/{y}/256/png8?app_id=YOUR_APP_ID&app_code=YOUR_APP_CODE 1 0 20

IMPORTANT: Use TAB as delimiter! enter image description here


Replace the placeholders YOUR_APP_ID and YOUR_APP_CODE with your app-id and your app-code and save the file into a folder that you will use for this plugin.


Open the TileLayerPlugin ( You will find the Plugin in the "Web"-Menu) and click on "Settings". Point to the folder where you saved your textfile:


enter image description here



Then you can just open the plugin whenever you need these baselayers and add them with one click: enter image description here


Where is composition tab in QGIS Composer to change page size?



I am trying to change the page size in the QGIS 3.0 Composer but I am not able to see the Composition tab. I have right clicked an empty space in the toolbar but did not see anything about composition. I am using Windows 7. I tried looking at the QGIS docs but they are still in testing.



Answer



It's sort of hidden, but still there. In QGIS 3.0, you can now have multiple pages in a single composer screen, and each page can be adjusted on its own. The pages are hidden from the Items panel, but all you need to do is right-click on any page and select Page properties. The settings you're used to seeing will pop into the Item properties tab:


page properties


Draw horizontal or vertical lines in QGIS?


I create a new shapefile layer as a line. Then I activated editing mode and want to draw vertical or horizontal lines with add feature but holding shift does not allow to draw a horizontal or vertical line (I used QGIS 2.14.4).


How can I draw horizontal or vertical lines as a shapefile?



Answer



The CADTools plugin has a feature named Orthogonal Digitizing.


While in editing mode of a line or polygon layer, holding ctrl allows to draw orthogonal lines.


Furthermore, the QAD plugin snaps to the horizontal or vertical axis when drawing a LINE object.


qgis processing - No output generated with "r.drain" GRASS module


I'm trying to do a Least Cost Path analysis, following upon these suggestions.


I got a DEM, created a slope layer from it, then used r.cost (Processing Toolbox) to create a cost surface. But when I run the r.drain module, I get an error and no file created. Here's the log with the error message:



A iniciar o algoritmo r.drain - Traces a flow through an elevation model on a raster map.... g.proj -c proj4="+proj=utm +zone=22 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" r.external input="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path/Cumulative-cost.tif" band=1 output=tmp14908042929517 --overwrite -o v.in.ogr min_area=0.0001 snap=-1 input="C.../Exercicios em teste/Novos exercicios/Least Cost Path" layer=Pontos-Alvo output=tmp14908042929518 --overwrite -o g.region -a n=9840380.0 s=9840130.0 e=785141.0 w=784667.0 res=1.0 r.drain input=tmp14908042929517 start_coordinates="(0,0)" start_points=tmp14908042929518 -c -a -n output=output41993ef1fbf245b780c12dd73c1c4c96 --overwrite g.region raster=output41993ef1fbf245b780c12dd73c1c4c96 r.out.gdal --overwrite -c createopt="TFW=YES,COMPRESS=LZW" input=output41993ef1fbf245b780c12dd73c1c4c96 output="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path/LeastCostPath.tif"


C:\PROGRA~1\QGIS2~1.14\bin>set HOME=C:\Users\



C:\PROGRA~1\QGIS2~1.14\bin>set GISRC=C:\Users....qgis2\processing\processing.gisrc7


C:\PROGRA~1\QGIS2~1.14\bin>set WINGISBASE=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0


C:\PROGRA~1\QGIS2~1.14\bin>set GISBASE=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0


C:\PROGRA~1\QGIS2~1.14\bin>set GRASS_PROJSHARE=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\share\proj


C:\PROGRA~1\QGIS2~1.14\bin>set GRASS_MESSAGE_FORMAT=plain


C:\PROGRA~1\QGIS2~1.14\bin>if "" == "" set PATH=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\bin;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\lib;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\Shapely-1.2.18-py2.7-win-amd64.egg\shapely\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\numpy\core;C:\PROGRA~1\QGIS2~1.14\apps\qgis-ltr\bin;C:\PROGRA~1\QGIS2~1.14\apps\Python27\Scripts;C:\PROGRA~1\QGIS2~1.14\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\WBem


C:\PROGRA~1\QGIS2~1.14\bin>if not "" == "" set PATH=C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\bin;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\lib;;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\bin;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\lib;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\Shapely-1.2.18-py2.7-win-amd64.egg\shapely\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\DLLs;C:\PROGRA~1\QGIS2~1.14\apps\Python27\lib\site-packages\numpy\core;C:\PROGRA~1\QGIS2~1.14\apps\qgis-ltr\bin;C:\PROGRA~1\QGIS2~1.14\apps\Python27\Scripts;C:\PROGRA~1\QGIS2~1.14\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\WBem


C:\PROGRA~1\QGIS2~1.14\bin>set GRASS_VERSION=7.0.0


C:\PROGRA~1\QGIS2~1.14\bin>if not "" == "" goto langset


C:\PROGRA~1\QGIS2~1.14\bin>FOR /F "usebackq delims==" %i IN ("C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\etc\winlocale") DO @set LANG=%i



C:\PROGRA~1\QGIS2~1.14\bin>set PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY


C:\PROGRA~1\QGIS2~1.14\bin>set PYTHONPATH=;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\etc\python;C:\PROGRA~1\QGIS2~1.14\apps\grass\grass-7.2.0\etc\wxpython\n


C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="MAPSET=PERMANENT"


C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="LOCATION=temp_location"


C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="LOCATION_NAME=temp_location"


C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="GISDBASE=C:\Users...\AppData\Local\Temp\processing961f3d92f1074413bf58edae90f70b98\grassdata"


C:\PROGRA~1\QGIS2~1.14\bin>g.gisenv.exe set="GRASS_GUI=text"


C:\PROGRA~1\QGIS2~1.14\bin>g.proj -c proj4="+proj=utm +zone=22 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" Default region was updated to the new projection, but if you have multiple mapsets g.region -d should be run in each to update the region from the default Projection information updated


C:\PROGRA~1\QGIS2~1.14\bin>r.external input="C:/Users/.../Exercicios em teste/Novos exercicios/Least Cost Path/Cumulative-cost.tif" band=1 output=tmp14908042929517 --overwrite -o ATENÇÃO: Over-riding projection check Reading band 1 of 1... r.external completo. Link to raster map created.


C:\PROGRA~1\QGIS2~1.14\bin>v.in.ogr min_area=0.0001 snap=-1 input="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path" layer=Pontos-Alvo output=tmp14908042929518 --overwrite -o Over-riding projection check Check if OGR layer contains polygons... 0..50..100 Importing 2 features (OGR layer )... 0..50..100 ----------------------------------------------------- A construir topologia para mapa vectorial ... Registando primitivas...



2 primitives registered 2 vertices registered A construir áreas... 0..50..100 0 areas built 0 isles built A anexar ilhas... A anexar centróides... 50..100 Número de nós: 0 Número de primitivos: 2 Número de pontos: 2 Número de linhas: 0 Número de fronteiras: 0 Número de centróides: 0 Número de áreas: 0 Número de ilhas: 0


C:\PROGRA~1\QGIS2~1.14\bin>g.region -a n=9840380.0 s=9840130.0 e=785141.0 w=784667.0 res=1.0


C:\PROGRA~1\QGIS2~1.14\bin>r.drain input=tmp14908042929517 start_coordinates="(0,0)" start_points=tmp14908042929518 -c -a -n output=output41993ef1fbf245b780c12dd73c1c4c96 --overwrite


Description: Traces a flow through an elevation model or cost surface on a raster map.


Keywords: raster, hydrology, cost surface


Usage: r.drain [-cand] input=name [direction=name] output=name [drain=name] [start_coordinates=east,north] [start_points=name[,name,...]] [--overwrite] [--help] [--verbose] [--quiet] [--ui]


Flags: -c Copia valores da célula de entrada -a Acumula valores da entrada ao longo do caminho -n Conta número de células ao longo do caminho -d The input raster map is a cost surface (direction surface must also be specified) --o Permitir que os ficheiros de saída reescrevam os ficheiros existentes --h Print usage summary --v Saída do módulo verbosa --q Saída do módulo quiet --qq Super quiet module output --ui Force launching GUI dialog


Parameters: input Name of input elevation or cost surface raster map direction Name of input movement direction map associated with the cost surface output Nome do mapa raster de saída drain Name for output drain vector map Recommended for cost surface made using knight's move start_coordinates Coordinates of starting point(s) (E,N) start_points Name of starting vector points map(s)


ERROR: Missing value for parameter


C:\PROGRA~1\QGIS2~1.14\bin>g.region raster=output41993ef1fbf245b780c12dd73c1c4c96 ERRO:Raster map not found



C:\PROGRA~1\QGIS2~1.14\bin>r.out.gdal --overwrite -c createopt="TFW=YES,COMPRESS=LZW" input=output41993ef1fbf245b780c12dd73c1c4c96 output="C:/.../Exercicios em teste/Novos exercicios/Least Cost Path/LeastCostPath.tif" ERRO:Raster map or group not found


C:\PROGRA~1\QGIS2~1.14\bin>exit Converting outputs Carregando as camadas resultantes


The following layers were not correctly generated. • Least cost path You can check the log messages to find more information about the execution of the algorithm



I can't figure out what am I doing wrong.


Can someone help with this issue?




shapefile - Expedite Near function in R for 10^9 coordinates?


Goal I want to find the geodesic distance between the closest hydrography feature to each of my lat/long coordinates.


I have hydrography data from New York state in a shapefile. I have many points, 10^9 number of coordinates in WGS1984 datum. There's about 20,000 features in my hydrography data which was originally in NAD1983.


I'm trying to find a way to expedite my code. This is what I've tried:


1) dist2Line from the package(geosphere): I keep getting the error: "returning Infno non-missing arguments to min". When I can get it to work (I haven't figured out why sometimes it works and sometimes it doesn't), it takes too long as well.


2) gDistance from package(rgeos): this also expects planar coordinates and takes too long (~43 sec for 300 pts).


3) st_nearest_feature from package (sf): This is fast (1 sec; 300 pts) but assumes the coordinates are planar. I get the index of the nearest hydro feature and I don't really know how to calculate distance easily from there (I suppose I could find a centroid for each hydro feature and calculate distance to that feature)?



4) st_nearest_points from package (sf): this takes too long (~100 sec, 300 pts) and assumes that coordinates are planar. It gives me linestring so I suppose I could calculate the distance between the two coordinates using a basic distance formula but the time & projection is not ideal.


I'm at a lost at how to proceed in a timely manner from here.


Potential Thoughts:


I've converted all of my hydrography features to WGS 1984 to work with it. Should I consider converting both files into planar coordinates? I'm not sure I understand well enough whether converting from unprojected to projected would cause any potential problems.


I just want the fastest way to process all of these points. I've been using fast_extract from package(velox) and (prioritizr) with raster data, and it's been incredibly fast. Something like that would be ideal.


I've tried to expedite this in ArcMap or R, and am open to either method. I've created a second question about ArcMap in the event somebody can think of a better me


Expedite Near function in ArcMap 10.7 for 10^9+ coordinates?




latitude longitude - Do XY coordinates refer to a shapefile, whereas Lat Long refers to the globe


I have data from City of New York


Instead of file showing Latitude Longitude it shows XY coordinate.


Please clarify, does XY coordinate refer to shapefile (which was not included), whereas Latitude Longitude references points on a globe?



Answer



After looking at your provided data, reading up the technical standards for spatial data of NYC and browsing through applicable gcs in QGIS, i was able to find something. Checked it with OSM-Map in QGIS. The red dots are your data aka graffito-locations and their conditions in NYC.


NYC Graffio-Locations NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet


ESRi WKID:102718 aka EPSG:2263




  • Try adding the CSV as textlayer. Separator is comma ' , '

  • Define x-coordinate as x and y-coordinate as y ;)

  • Uncheck gms-coords (red circle)

  • After confirmation define the GCS with EPSG: 2263 QGIS 'Add text as layer'-window


AND finally answering your question: The provided x/y-coords-pairs are representing points in a projected coordinate system (here WKID:102718 EPSG: 2263) with cartesian axes.


P.S.: Please note that i'm not from the US, so any additonal insight on nyc gcs is welcome.


arcgis desktop - Why is it important to use feature layers in ModelBuilder?


I am trying to understand creation of a geoprocess with ModelBuilder, but I don't know why it's important to use feature layers instead of feature classes when creating a geoprocess with ModelBuilder. Can someone please explain why?



Answer



Models may have many sub process output layers depending on their size and complexity. To eliminate files being written onto your hard disk, some tools make you use feature layers (e.g. Iterate Feature Selection, or Select by Attribute). Feature layers are temporary and will not persist after your model ends.


See Make Feature Layer


geoserver - How to avoid Pink tiles when DB view/Table is empty?


I have views that are spatial in a sense that they select some spatial column from other table. This table is published using geoserver. This table is live and sometime has no data at all. When the table has no data the wms displayed is all red and error in firebug console is: enter image description here


The WMS returned:


>  > ServiceExceptionReport SYSTEM
> "http://192.168.70.65:80/geoserver/schemas/wms/1.1.1/WMS_exception_1_1_1.dtd">

> java.lang.NullPointerException
> null
>


The Code:


function init(){    
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 1;
OpenLayers.Util.onImageLoadErrorColor = "transparent";

map = new OpenLayers.Map('map', {

projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
numZoomLevels: 21,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,20037508, 20037508.34),
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher({'ascending':false}),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.MousePosition(),

new OpenLayers.Control.OverviewMap(),
new OpenLayers.Control.KeyboardDefaults()
]


});

Using GeoExt:






























Answer



the problem comes from the way you declare layers when inisialising your map. so this piece of your code:


var map = new ol.Map({
layers: [baseLayers, layerVector],
loadTilesWhileInteracting: true,
target: document.getElementById('map'),
view: new ol.View({

//projection:projection
center: ol.proj.transform(
[-116, 42], 'EPSG:4326', 'EPSG:3857'),
zoom: 6
})
});

should change to this:


var layersToAdd = baseLayers.concat(layerVector);
var map = new ol.Map({

layers: layersToAdd ,
loadTilesWhileInteracting: true,
target: document.getElementById('map'),
view: new ol.View({
//projection:projection
center: ol.proj.transform(
[-116, 42], 'EPSG:4326', 'EPSG:3857'),
zoom: 6
})
});


It seems they way you pass layers on map is not a proper array. so concatenating the array of base layers with the vector layer, forms a proper array. I have also made o fiddle check it here to test. There are slight mods of your code but the piece I mentioned above seems to cause the problem. Hope to help you!!!!


arcgis desktop - Does ModelBuilder have Iterate Field Values bug when model run without being in Edit mode?



I think I may have found a ModelBuilder bug.


Would it be possible for someone to try and follow my procedure to see if they agree, and if so, to try and suggest a workaround that still uses ModelBuilder, other than only ever running this model while it is open for editing?


I already know how to do this using ArcPy, but I was trying to show how easy it was to do using ModelBuilder too.


I'm happy to accept an answer without it containing a workaround because what I am really after is a sanity check on my procedure and observed results. If it is a bug I would be keen to know an NIM number and whether it is fixed in the ModelBuilder from either or both of the ArcMap and ArcGIS Pro applications of ArcGIS 10.3 for Desktop.


I am using ArcGIS 10.2.2 for Desktop and a File Geodatabase. I have my Geoprocessing environment set to overwrite.




  1. I used Create Fishnet to create a 2x2 fishnet with cells 1x1 in size called FishnetFC, added a field called Name and updated that field so that the attribute table has the appearance below. Using any polygon feature class with any field of type text populated with unique vales should be fine to test with.


enter image description here



  1. I then made the model below which has no parameters


enter image description here



  1. I configured the Iterate Field Values tool as below



enter image description here



  1. I configured the Select tool as below


enter image description here



  1. The Value variable is a precondition to the Select tool but that does not appear to be important because I have tried with and without that.

  2. When I run the model while it is open it produces four feature classes called FC1, FC2, FC3 and FC4 as expected



The output is:


Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:03:02 2014
Succeeded at Tue Nov 11 17:03:02 2014 (Elapsed Time: 0.06 seconds)
Executing (Select): Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC1 "Name = 'FC1'"
Start Time: Tue Nov 11 17:03:02 2014
Succeeded at Tue Nov 11 17:03:02 2014 (Elapsed Time: 0.44 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:03:03 2014
Succeeded at Tue Nov 11 17:03:03 2014 (Elapsed Time: 0.00 seconds)

Executing (Select): Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC2 "Name = 'FC2'"
Start Time: Tue Nov 11 17:03:03 2014
Succeeded at Tue Nov 11 17:03:03 2014 (Elapsed Time: 0.46 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:03:03 2014
Succeeded at Tue Nov 11 17:03:03 2014 (Elapsed Time: 0.00 seconds)
Executing (Select): Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC3 "Name = 'FC3'"
Start Time: Tue Nov 11 17:03:04 2014
Succeeded at Tue Nov 11 17:03:04 2014 (Elapsed Time: 0.44 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #

Start Time: Tue Nov 11 17:03:04 2014
Succeeded at Tue Nov 11 17:03:04 2014 (Elapsed Time: 0.00 seconds)
Executing (Select): Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC4 "Name = 'FC4'"
Start Time: Tue Nov 11 17:03:04 2014
Succeeded at Tue Nov 11 17:03:05 2014 (Elapsed Time: 0.39 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:03:05 2014
Succeeded at Tue Nov 11 17:03:05 2014 (Elapsed Time: 0.00 seconds)



  1. When I save and close the model, before running it that way instead it produces only two feature classes called FC1 and FC2 - I think this has to be a bug!


This time the output is unexpectedly as below. I have placed asterisks (**) where it departs from what I would have expected.


Executing: SelectByAttribute
Start Time: Tue Nov 11 17:04:34 2014
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:04:34 2014
Succeeded at Tue Nov 11 17:04:34 2014 (Elapsed Time: 0.05 seconds)
Executing (Select): Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC1 "Name = 'FC1'"
Start Time: Tue Nov 11 17:04:34 2014

Succeeded at Tue Nov 11 17:04:34 2014 (Elapsed Time: 0.28 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:04:34 2014
Succeeded at Tue Nov 11 17:04:34 2014 (Elapsed Time: 0.00 seconds)
Executing (Select): Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC2 "Name = 'FC2'"
Start Time: Tue Nov 11 17:04:34 2014
Succeeded at Tue Nov 11 17:04:35 2014 (Elapsed Time: 0.27 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:04:35 2014
Succeeded at Tue Nov 11 17:04:35 2014 (Elapsed Time: 0.00 seconds)

Executing (Select): **Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC1 "Name = 'FC3'"**
Start Time: Tue Nov 11 17:04:35 2014
Succeeded at Tue Nov 11 17:04:35 2014 (Elapsed Time: 0.39 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #
Start Time: Tue Nov 11 17:04:35 2014
Succeeded at Tue Nov 11 17:04:35 2014 (Elapsed Time: 0.00 seconds)
Executing (Select): **Select C:\polygeo\test.gdb\FishnetFC C:\polygeo\test.gdb\FC1 "Name = 'FC4'"**
Start Time: Tue Nov 11 17:04:35 2014
Succeeded at Tue Nov 11 17:04:36 2014 (Elapsed Time: 0.45 seconds)
Executing (Iterate Field Values): IterateFieldValues C:\polygeo\test.gdb\FishnetFC Name String false false #

Start Time: Tue Nov 11 17:04:36 2014
Succeeded at Tue Nov 11 17:04:36 2014 (Elapsed Time: 0.00 seconds)
Succeeded at Tue Nov 11 17:04:36 2014 (Elapsed Time: 1.89 seconds)


qgis - Dropping z dimension programmatically


It seems there is no geoalgorithm to drop z values in the QGIS processing toolbox. Can this be done programmatically using the Python console? At the moment I have to save the layer with unchecked 'Include z-dimension' checkbox (non automatic geometry type):



enter image description here



Answer




For future reference - QGIS 3 includes a drop z value processing algorithm


arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...