Skip to content

Commit

Permalink
Can't use 'import' as a function parameter name in Python
Browse files Browse the repository at this point in the history
Can't use 'import' as a function parameter name in Python
  • Loading branch information
jblindsay committed Nov 22, 2018
1 parent f8af226 commit a758dac
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 32 deletions.
Binary file modified WhiteboxToolsManual.pdf
Binary file not shown.
33 changes: 20 additions & 13 deletions manual/WhiteboxToolsManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ derived. The *foreign key* (`--fkey` flag), the identifying field within the
second table that corresponds with the data contained within the primary key in the table, must be
specified. Both the primary and foreign keys should either be strings (text) or integer values.
*Fields containing decimal values are not good candidates for keys.* Lastly, the names of the field
within the second file to include in the merge operation can also be input (`--import`). If the
`--import` field is not input, all fields in the attribute table of the second file, that are not
within the second file to include in the merge operation can also be input (`--import_field`). If the
`--import_field` field is not input, all fields in the attribute table of the second file, that are not
the foreign key nor FID, will be imported to the first table.
Merging works for one-to-one and many-to-one database relations. A *one-to-one* relations exists when
Expand Down Expand Up @@ -723,7 +723,7 @@ will correspond to only one foreign key containing the population and area data.
-\-pkey Primary key field
-\-i2, -\-input2 Input foreign vector file (i.e. source of data to be imported)
-\-fkey Foreign key field
-\-import Imported field (all fields will be imported if not specified)
-\-import_field Imported field (all fields will be imported if not specified)
*Python function*:
Expand All @@ -734,7 +734,7 @@ join_tables(
pkey,
input2,
fkey,
import,
import_field,
callback=default_callback)
~~~~
Expand All @@ -743,7 +743,7 @@ join_tables(
```
>>./whitebox_tools -r=JoinTables -v --wd="/path/to/data/" ^
--i1=properties.shp --pkey=TYPE --i2=land_class.shp ^
--fkey=VALUE --import=NEW_VALUE
--fkey=VALUE --import_field=NEW_VALUE


```
Expand Down Expand Up @@ -803,7 +803,7 @@ header row, i.e. the first row must contain information about the names of the v
CSV file that corresponds with the data contained within the *primary key* in the table, must also
be specified. Both the primary and foreign keys should either be strings (text) or integer values.
*Fields containing decimal values are not good candidates for keys.* Lastly, the user may optionally
specify the name of a field within the CSV file to import in the merge operation (`--import` flag).
specify the name of a field within the CSV file to import in the merge operation (`--import_field` flag).
If this flag is not specified, all of the fields within the CSV, with the exception of the foreign
key, will be appended to the attribute table.
Expand Down Expand Up @@ -834,7 +834,7 @@ will correspond to only one foreign key containing the population and area data.
-\-pkey Primary key field
-\-csv Input CSV file (i.e. source of data to be imported)
-\-fkey Foreign key field
-\-import Imported field (all fields will be imported if not specified)
-\-import_field Imported field (all fields will be imported if not specified)
*Python function*:
Expand All @@ -845,7 +845,7 @@ merge_table_with_csv(
pkey,
csv,
fkey,
import=None,
import_field=None,
callback=default_callback)
~~~~
Expand All @@ -855,9 +855,9 @@ merge_table_with_csv(
>>./whitebox_tools -r=MergeTableWithCsv -v ^
--wd="/path/to/data/" -i=properties.shp --pkey=TYPE ^
--csv=land_class.csv --fkey=VALUE ^
--import=NEW_VALUE
>>./whitebox_tools -r=MergeTableWithCsv -v ^
--wd="/path/to/data/" -i=properties.shp --pkey=TYPE ^
--import_field=NEW_VALUE
>>./whitebox_tools -r=MergeTableWithCsv ^
-v --wd="/path/to/data/" -i=properties.shp --pkey=TYPE ^
--csv=land_class.csv --fkey=VALUE


Expand Down Expand Up @@ -3458,6 +3458,7 @@ resulting from the overlay operation.
-i, -\-input Input vector file
-\-overlay Input overlay vector file
-o, -\-output Output vector file
-\-snap Snap tolerance
*Python function*:
Expand All @@ -3467,14 +3468,16 @@ intersect(
i,
overlay,
output,
snap=0.0,
callback=default_callback)
~~~~
*Command-line Interface*:
```
>>./whitebox_tools -r=Intersect -v --wd="/path/to/data/" ^
-input=layer1.shp --overlay=layer2.shp -o=out_file.shp
-input=layer1.shp --overlay=layer2.shp -o=out_file.shp ^
--snap=0.0000001


```
Expand Down Expand Up @@ -3975,6 +3978,7 @@ resulting from the overlay operation.
-i, -\-input Input vector file
-\-overlay Input overlay vector file
-o, -\-output Output vector file
-\-snap Snap tolerance
*Python function*:
Expand All @@ -3984,6 +3988,7 @@ symmetrical_difference(
i,
overlay,
output,
snap=0.0,
callback=default_callback)
~~~~
Expand All @@ -3992,7 +3997,7 @@ symmetrical_difference(
```
>>./whitebox_tools -r=SymmetricalDifference -v ^
--wd="/path/to/data/" -input=layer1.shp --overlay=layer2.shp ^
-o=out_file.shp
-o=out_file.shp --snap=0.0000001


```
Expand Down Expand Up @@ -15509,6 +15514,8 @@ tributary_identifier(
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for more details.
* Release Notes: *
******************

Version 0.12.0 (XX-XX-2018)
Version 0.12.0 (22-11-2018)
- The following tools were added to the project:
BlockMaximumGridding
BlockMinimumGridding
Expand Down
12 changes: 6 additions & 6 deletions src/tools/data_tools/join_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Prof. John Lindsay
Created: 07/10/2018
Last Modified: 12/10/2018
Last Modified: 22/11/2018
License: MIT
*/

Expand All @@ -23,8 +23,8 @@ use vector::{FieldData, Shapefile};
/// second table that corresponds with the data contained within the primary key in the table, must be
/// specified. Both the primary and foreign keys should either be strings (text) or integer values.
/// *Fields containing decimal values are not good candidates for keys.* Lastly, the names of the field
/// within the second file to include in the merge operation can also be input (`--import`). If the
/// `--import` field is not input, all fields in the attribute table of the second file, that are not
/// within the second file to include in the merge operation can also be input (`--import_field`). If the
/// `--import_field` field is not input, all fields in the attribute table of the second file, that are not
/// the foreign key nor FID, will be imported to the first table.
///
/// Merging works for one-to-one and many-to-one database relations. A *one-to-one* relations exists when
Expand Down Expand Up @@ -111,7 +111,7 @@ impl JoinTables {

parameters.push(ToolParameter {
name: "Imported Field".to_owned(),
flags: vec!["--import".to_owned()],
flags: vec!["--import_field".to_owned()],
description: "Imported field (all fields will be imported if not specified)."
.to_owned(),
parameter_type: ParameterType::VectorAttributeField(
Expand All @@ -134,7 +134,7 @@ impl JoinTables {
short_exe += ".exe";
}
let usage = format!(
">>.*{0} -r={1} -v --wd=\"*path*to*data*\" --i1=properties.shp --pkey=TYPE --i2=land_class.shp --fkey=VALUE --import=NEW_VALUE",
">>.*{0} -r={1} -v --wd=\"*path*to*data*\" --i1=properties.shp --pkey=TYPE --i2=land_class.shp --fkey=VALUE --import_field=NEW_VALUE",
short_exe, name
).replace("*", &sep);

Expand Down Expand Up @@ -228,7 +228,7 @@ impl WhiteboxTool for JoinTables {
} else {
args[i + 1].to_string()
};
} else if flag_val == "-import" {
} else if flag_val == "-import_field" {
import_field = if keyval {
vec[1].to_string()
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/tools/data_tools/merge_table_with_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This tool is part of the WhiteboxTools geospatial analysis library.
Authors: Prof. John Lindsay
Created: 11/10/2018
Last Modified: 12/10/2018
Last Modified: 22/11/2018
License: MIT
*/

Expand All @@ -29,7 +29,7 @@ use vector::{AttributeField, FieldData, FieldDataType, Shapefile};
/// CSV file that corresponds with the data contained within the *primary key* in the table, must also
/// be specified. Both the primary and foreign keys should either be strings (text) or integer values.
/// *Fields containing decimal values are not good candidates for keys.* Lastly, the user may optionally
/// specify the name of a field within the CSV file to import in the merge operation (`--import` flag).
/// specify the name of a field within the CSV file to import in the merge operation (`--import_field` flag).
/// If this flag is not specified, all of the fields within the CSV, with the exception of the foreign
/// key, will be appended to the attribute table.
///
Expand Down Expand Up @@ -114,7 +114,7 @@ impl MergeTableWithCsv {

parameters.push(ToolParameter {
name: "Imported Field".to_owned(),
flags: vec!["--import".to_owned()],
flags: vec!["--import_field".to_owned()],
description: "Imported field (all fields will be imported if not specified)."
.to_owned(),
parameter_type: ParameterType::VectorAttributeField(
Expand All @@ -137,7 +137,7 @@ impl MergeTableWithCsv {
short_exe += ".exe";
}
let usage = format!(
">>.*{0} -r={1} -v --wd=\"*path*to*data*\" -i=properties.shp --pkey=TYPE --csv=land_class.csv --fkey=VALUE --import=NEW_VALUE
">>.*{0} -r={1} -v --wd=\"*path*to*data*\" -i=properties.shp --pkey=TYPE --csv=land_class.csv --fkey=VALUE --import_field=NEW_VALUE
>>.*{0} -r={1} -v --wd=\"*path*to*data*\" -i=properties.shp --pkey=TYPE --csv=land_class.csv --fkey=VALUE",
short_exe, name
).replace("*", &sep);
Expand Down
21 changes: 13 additions & 8 deletions whitebox_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def list_tools(self, keywords=[]):




##############
# Data Tools #
##############
Expand Down Expand Up @@ -422,7 +423,7 @@ def export_table_to_csv(self, i, output, headers=True, callback=None):
if headers: args.append("--headers")
return self.run_tool('export_table_to_csv', args, callback) # returns 1 if error

def join_tables(self, input1, pkey, input2, fkey, import, callback=None):
def join_tables(self, input1, pkey, input2, fkey, import_field, callback=None):
"""Merge a vector's attribute table with another table based on a common field.
Keyword arguments:
Expand All @@ -431,15 +432,15 @@ def join_tables(self, input1, pkey, input2, fkey, import, callback=None):
pkey -- Primary key field.
input2 -- Input foreign vector file (i.e. source of data to be imported).
fkey -- Foreign key field.
import -- Imported field (all fields will be imported if not specified).
import_field -- Imported field (all fields will be imported if not specified).
callback -- Custom function for handling tool text outputs.
"""
args = []
args.append("--input1='{}'".format(input1))
args.append("--pkey='{}'".format(pkey))
args.append("--input2='{}'".format(input2))
args.append("--fkey='{}'".format(fkey))
args.append("--import='{}'".format(import))
args.append("--import_field='{}'".format(import_field))
return self.run_tool('join_tables', args, callback) # returns 1 if error

def lines_to_polygons(self, i, output, callback=None):
Expand All @@ -456,7 +457,7 @@ def lines_to_polygons(self, i, output, callback=None):
args.append("--output='{}'".format(output))
return self.run_tool('lines_to_polygons', args, callback) # returns 1 if error

def merge_table_with_csv(self, i, pkey, csv, fkey, import=None, callback=None):
def merge_table_with_csv(self, i, pkey, csv, fkey, import_field=None, callback=None):
"""Merge a vector's attribute table with a table contained within a CSV text file.
Keyword arguments:
Expand All @@ -465,15 +466,15 @@ def merge_table_with_csv(self, i, pkey, csv, fkey, import=None, callback=None):
pkey -- Primary key field.
csv -- Input CSV file (i.e. source of data to be imported).
fkey -- Foreign key field.
import -- Imported field (all fields will be imported if not specified).
import_field -- Imported field (all fields will be imported if not specified).
callback -- Custom function for handling tool text outputs.
"""
args = []
args.append("--input='{}'".format(i))
args.append("--pkey='{}'".format(pkey))
args.append("--csv='{}'".format(csv))
args.append("--fkey='{}'".format(fkey))
if import is not None: args.append("--import='{}'".format(import))
if import_field is not None: args.append("--import_field='{}'".format(import_field))
return self.run_tool('merge_table_with_csv', args, callback) # returns 1 if error

def merge_vectors(self, inputs, output, callback=None):
Expand Down Expand Up @@ -1560,20 +1561,22 @@ def highest_position(self, inputs, output, callback=None):
args.append("--output='{}'".format(output))
return self.run_tool('highest_position', args, callback) # returns 1 if error

def intersect(self, i, overlay, output, callback=None):
def intersect(self, i, overlay, output, snap=0.0, callback=None):
"""Identifies the parts of features in common between two input vector layers.
Keyword arguments:
i -- Input vector file.
overlay -- Input overlay vector file.
output -- Output vector file.
snap -- Snap tolerance.
callback -- Custom function for handling tool text outputs.
"""
args = []
args.append("--input='{}'".format(i))
args.append("--overlay='{}'".format(overlay))
args.append("--output='{}'".format(output))
args.append("--snap={}".format(snap))
return self.run_tool('intersect', args, callback) # returns 1 if error

def line_intersections(self, input1, input2, output, callback=None):
Expand Down Expand Up @@ -1770,20 +1773,22 @@ def sum_overlay(self, inputs, output, callback=None):
args.append("--output='{}'".format(output))
return self.run_tool('sum_overlay', args, callback) # returns 1 if error

def symmetrical_difference(self, i, overlay, output, callback=None):
def symmetrical_difference(self, i, overlay, output, snap=0.0, callback=None):
"""Outputs the features that occur in one of the two vector inputs but not both, i.e. no overlapping features.
Keyword arguments:
i -- Input vector file.
overlay -- Input overlay vector file.
output -- Output vector file.
snap -- Snap tolerance.
callback -- Custom function for handling tool text outputs.
"""
args = []
args.append("--input='{}'".format(i))
args.append("--overlay='{}'".format(overlay))
args.append("--output='{}'".format(output))
args.append("--snap={}".format(snap))
return self.run_tool('symmetrical_difference', args, callback) # returns 1 if error

def union(self, i, overlay, output, snap=0.0, callback=None):
Expand Down

0 comments on commit a758dac

Please sign in to comment.