# CSV Geometry Export - QGIS Plugin

Export vector layers to CSV with multiple geometry formats. Part of **MAS Vector Processing** tools.

## Features

### Supported Export Formats

| Format              | Description                | Example Output                     |
| ------------------- | -------------------------- | ---------------------------------- |
| **WKT**             | Well-Known Text (default)  | `POINT(30 10)`                     |
| **WKB**             | Well-Known Binary (hex)    | `0101000000...`                    |
| **EWKT**            | Extended WKT with SRID     | `SRID=4326;POINT(30 10)`           |
| **EWKB**            | Extended WKB with SRID     | `0101000020E6100000...`            |
| **GeoJSON**         | GeoJSON geometry object    | `{"type":"Point",...}`             |
| **KML**             | KML coordinates element    | `<coordinates>30,10</coordinates>` |
| **Earth Engine**    | Google Earth Engine format | `ee.Geometry.Point([30, 10])`      |
| **X-Y Coordinates** | Separate lon/lat columns   | Two columns with centroid          |

### Key Features

- **Multiple Geometry Formats**: Export to WKT, WKB, GeoJSON, KML, Earth Engine, and more
- **Input Layer Selection**: Dropdown with all loaded layers + browse for files
- **Keep Original Geometry**: Option to add WKT column alongside any format
- **X-Y Coordinates**: Extracts centroid for polygons/lines
- **CRS Transformation**: Reproject geometry on export
- **Field Selection**: Choose and rename fields to export
- **Selected Features Only**: Export only selected features
- **Multiple Separators**: Comma, semicolon, tab, pipe, space
- **Encoding Options**: UTF-8, Latin1, and many more

## Installation

### From QGIS Plugin Manager
1. Go to `Plugins` → `Manage and Install Plugins`
2. Search for "CSV Geometry Export"
3. Click `Install Plugin`

### Manual Installation
1. Download the plugin ZIP file
2. Extract to your QGIS plugins directory:
   - **Windows**: `%APPDATA%\QGIS\QGIS3\profiles\default\python\plugins\`
   - **Linux**: `~/.local/share/QGIS/QGIS3/profiles/default/python/plugins/`
   - **macOS**: `~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/`
3. Restart QGIS and enable the plugin

## Usage

### From Context Menu (Recommended)
1. Right-click on a vector layer in the Layers panel
2. Select **"Export as CSV with Geometry"**
3. Configure options and click OK

### From Toolbar/Menu
1. Go to `MAS Vector Processing` → `CSV Geometry Export`
2. Or click the toolbar button
3. Select input layer from dropdown
4. Configure options and click OK

## Configuration Options

| Option                     | Description                                  |
| -------------------------- | -------------------------------------------- |
| **Input Layer**            | Select from loaded layers or browse for file |
| **Output File**            | Path for the exported CSV                    |
| **Geometry Format**        | WKT, WKB, GeoJSON, KML, etc.                 |
| **Keep Original Geometry** | Add WKT column alongside chosen format       |
| **Geometry Column Name**   | Custom name for geometry column              |
| **CRS**                    | Target coordinate reference system           |
| **Separator**              | Comma, semicolon, tab, pipe, space           |
| **Encoding**               | UTF-8, Latin1, CP1252, etc.                  |
| **Selected Features Only** | Export only selected features                |

## Example Output

### WKT Format
```csv
id,name,geometry
1,Location A,"POINT(77.5946 12.9716)"
2,Location B,"POLYGON((0 0,1 0,1 1,0 1,0 0))"
```

### X-Y Coordinates with Original Geometry
```csv
id,name,longitude,latitude,org_geom
1,Area 1,77.5946,12.9716,"POLYGON((77 12,78 12,78 13,77 13,77 12))"
```

## Requirements

- QGIS 3.0 or higher
- No additional Python packages required

## Author

**Mirjan Ali Sha**
- Email: mastools.help@gmail.com
- GitHub: [Mirjan-Ali-Sha](https://github.com/Mirjan-Ali-Sha)

## License

GPL v2 or later

## Changelog

### Version 1.0.2 (2024-12-21)
- Added geometry format dropdown (WKT, WKB, EWKT, EWKB, GeoJSON, KML, Earth Engine, X-Y)
- Added "Keep original geometry column" option
- Added input layer selection dropdown with browse button
- X-Y format uses centroid for non-point geometries
- Improved settings persistence

### Version 1.0.1
- Added more separator options

### Version 1.0.0
- Initial release
