.. _impexp_cli_delete_command: Delete command --------------- **Synopsis** .. code-block:: bash impexp delete [-ahvV] [--ade-extensions=] [-c=] [--delete-log=] [--log-file=] [--log-level=] [-m=] [--pid-file=] [--plugins=] [--use-plugin=[, ...]]... [[-g]] [[--lineage=] [--updating-person=] [--reason-for-update=]] [[-t=<[prefix:]name>[,< [prefix:]name>...] [-t=<[prefix:]name>[,<[prefix:] name>...]]... [--namespace=[, ...]]...] [[-r=] [-R=]] [-i=[,...] [-i=[,...]]...] [--db-id=[,...] [--db-id=[,...]]...] [-b= [--bbox-mode=]] [[--count=] [--start-index=]] [-s= Provide an SQL SELECT statement to be used as SQL filter when querying the database. In general, any SELECT statement can be used as long as it returns a list of database IDs of the selected city objects (see :numref:`impexp_export_sql_filter` for more information). You can also use an @-file to provide the SELECT statement (see :numref:`impexp_cli_argument_files`). .. option:: -q, --xml-query= This option allows you to use a full-fledged XML query expression as filter for the delete operation. Make sure the query expression is valid and adheres to the specification for XML query expressions provided in :numref:`impexp_xml_queries_chapter`. You can also use an @-file to provide the query expression (see :numref:`impexp_cli_argument_files`). This option **cannot be used with any other filter option** of the ``delete`` command. **Delete list options** You can also pass a delete list to the ``delete`` command to control which city objects should be deleted. A delete list can be used in addition to or instead of the above filter options. Delete lists are simple comma-separated values (CSV) files that provide the identifiers of the city objects to be deleted. Each identifier must be put on a separate line (row) of the file, and each line may contain additional values (columns) separated by a delimiter (typically a single reserved character such as comma, semicolon, tab, etc.). The first record may be reserved as header containing a list of column names. Usually, every row has the same sequence of columns. If a line starts with a predefined comment marker (typically a single reserved character such as ``#``), the entire row is ignored and skipped. Due to their simple structure, delete lists can be easily created with external tools and processes. The following snippet shows an example of a simple delete list that can be used with the ``delete`` command. It just provides an identifier per row. The first line is used as header. .. code-block:: bash :linenos: GMLID ID_0815 ID_0816 ID_0817 ID_0818 ... The following options let you define the layout and reserved characters of the delete list you want to use with the ``delete`` command. You can provide one or more CSV files as input for the delete list. If more than one file is specified, make sure all of them have the same layout and structure. .. option:: -f, --delete-list=[,...] One or more CSV files to use as delete list for the delete operation. .. option:: -w, --delete-list-preview Use this option to get a preview of the first few lines of the delete list when applying the provided options for parsing and interpreting the delete list. This preview is very helpful to adapt and specify the delimiter character(s), quoting rules, header information, identifier column name or index, etc. The preview is printed to the console. If more than one CSV file has been specified for the delete list, the preview is generated for the first file only. .. option:: -n, --id-column-name= Name of the column that holds the identifier value. Using this option only makes sense if the delete list contains a header line. Otherwise, use the :option:`--id-column-index` option to specify the column index. .. option:: -I, --id-column-index= Index of the column that holds the identifier value. The first column of a row has the index 1. If this option is omitted, the value of the first column of each row will be used as identifier by default. This option is mutually exclusive with the :option:`--id-column-name` option (only specify one). .. option:: -C, --id-column-type= Specify the type of the identifier. Allowed values are ``resource`` and ``db``. When choosing ``resource``, the identifiers provided in the delete list are interpreted as object identifiers (e.g., *gml:id* in CityGML) and are therefore matched against the GMLID column of the CITYOBJECT table. In contrast, the identifiers are taken as database IDs and checked against the ID column of the CITYOBJECT table when selecting ``db`` instead. The default value is ``resource``. .. option:: --[no-]header Define whether or not the delete list uses a header line. By default, the delete operation assumes that the first line contains header information. .. option:: -D, --delimiter= Specify the delimiter used for separating values in the delete list. By default, a comma ``,`` is assumed as delimiter. The provided delimiter may consist of more than one character. .. option:: -Q, --quote= The values in the delete list may be quoted (i.e., enclosed by a reserved character). This option lets you define the character used as quote (default: ``"``). Only single characters are allowed as value. .. option:: --quote-escape= If the delete list contains quoted values, define the character used for escaping embedded quote characters. The default escape character is ``"``. Only single characters are allowed as value. .. option:: -M, --comment-marker= Specify the character used as comment marker in the delete list. Any line starting with this comment marker is interpreted as comment and, thus, will be ignored. The default comment marker is ``#``. Only single characters are allowed as value. .. option:: --csv-encoding= Define the encoding of the delete list using a IANA-based character encoding name. UTF-8 is assumed as default encoding. .. include:: database-options.rst **Examples** .. code-block:: bash $ impexp delete -H localhost -d citydb_v4 -u citydb_user -p my_password Delete all city objects from the database. The 3DCityDB to connect to is supposed to be running on a PostgreSQL database on the same machine. The connection will be established to the ``citydb_v4`` database with the user ``citydb_user`` and the password ``my_password``. .. caution:: Be very careful with the above example and only use it in case you are absolutely sure. **There will be no confirmation prompt and no undo operation** (which is also true for all further examples...). If you really want to clean the entire database, the ``cleanup_schema`` database function provided by the 3DCityDB should be your preferred choice simply because it is much faster. .. code-block:: bash $ impexp delete -H localhost -d citydb_v4 -u citydb_user -p my_password \ -m terminate -v \ -t Building -b 13.3508824,52.4799281,13.3578297,52.4862805,4326 \ --bbox-mode=within Only terminate ``Building`` features ``within`` the given bounding box. The affected buildings are kept in database but marked as terminated by setting their *terminationDate* attribute. The entire process is run in preview mode. Thus, a summary overview of the number of affected feature is printed to the console but nothing will be committed to the database. .. code-block:: bash $ impexp delete -H localhost -d citydb_v4 -u citydb_user -p my_password \ -m terminate -g \ -s "select cityobject_id from cityobject_genericattrib \ where attrname='energy_level' and realval < 12" \ --count 20 Terminate the first 20 top-level city objects satisfying the given SQL SELECT statement. Afterwards, global appearances not referencing a city object anymore will be deleted from the database. .. code-block:: bash $ impexp delete -H localhost -d citydb_v4 -u citydb_user -p my_password \ -f imported-features.log -I 2 -C db Only delete those top-level city objects having a database ID that is contained in the provided delete list ``imported-features.log``. The command uses default values for parsing and interpreting the delete list except for the index of the column that holds the identifier values, which is set to 2, and the type of the identifier, which is set to ``db``. The above example has been chosen deliberately because it illustrates how to use an import log file created by a CityGML/CityJSON import operation as delete list for the ``delete`` command. The general layout and content of an import log file is discussed in :numref:`impexp_import_preferences_import_logs`. The snippet below shows an example. .. code-block:: bash :linenos: #3D City Database Importer/Exporter, version "4.3.0" #Database connection: citydb_user@localhost:5432/devel #Timestamp: 2021-04-19 21:30:40 FEATURE_TYPE,CITYOBJECT_ID,GMLID_IN_FILE,INPUT_FILE Building,532,BLDG_0003000000106562,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,540,BLDG_00030000001065f4,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,552,BLDG_0003000000106543,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,556,BLDG_0003000a000afa94,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,563,BLDG_0003000a0019a1c6,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,533,BLDG_0003000000106686,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,542,BLDG_0003000a000afacf,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,548,BLDG_0003000a000afb3b,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,560,BLDG_0003000e009b5355,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml Building,568,BLDG_0003000b003d0d1b,C:\data\citygml\berlin\gasometer\tile_0_0\Gasometer.gml #Import successfully finished. The import log uses a comma ``,`` as delimiter. Lines 1-3 and line 15 are comments starting with the comment marker ``#`` and should therefore be ignored. Line 4 is used as header to provide column names for the subsequent rows. The actual content is therefore provided in lines 5-14. Each row consists of four columns, and the second column ``CITYOBJECT_ID`` contains the database ID of the imported top-level features. As you can see from the above example, the default CSV options of the ``delete`` command are already suited to correctly identify the comments, the header, and the separate columns of the import log file. As mentioned above, we only have to specify that we want to use database IDs as identifiers and provide the correct column index on the command line. .. note:: The third column ``GMLID_IN_FILE`` of the import log file holds the object identifier of the imported city objects. To use this object identifier in the delete process, you just have to use ``-I 3`` to specify the third column and omit the additional ``-C db`` option. **However, be careful when using the** ``GMLID_IN_FILE`` **values because the object identifiers in the database might be different due to import preference settings.**