MobilityDB 1.3
Loading...
Searching...
No Matches
Macros | Functions
popplaces_kmeans.c File Reference

A simple program that reads from a CSV file obtained from 1:10M populated places from Natural Earth. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <meos.h>
#include <meos_geo.h>

Macros

#define MAX_LENGTH_LINE   1024
 
#define MAX_ROWS   50000
 
#define NO_INSTANTS_BATCH   1000
 

Functions

int main (void)
 

Detailed Description

A simple program that reads from a CSV file obtained from 1:10M populated places from Natural Earth.

https://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-populated-places/ https://www.naturalearthdata.com/ and applies the PostGIS function ST_ClusterKMeans to the entire file.

This file simply reproduces in MEOS Paul Ramsey's blog https://www.crunchydata.com/blog/postgis-clustering-with-k-means Therefore, the program corresponds to the following SQL query

SELECT name, pop_max, geom,
ST_ClusterKMeans(geom, 10) OVER () AS cluster
FROM popplaces;

The program can be build as follows

gcc -Wall -g -I/usr/local/include -o popplaces_kmeans popplaces_kmeans.c -L/usr/local/lib -lmeos
CREATE TABLE popplaces_geographic_meos (
name text,
pop_max int,
geom geometry(Point, 4326),
cluster integer);
COPY popplaces_geographic_meos
FROM '/home/esteban/src/MobilityDB/meos/examples/data/popplaces_new.csv'
DELIMITER ',' CSV HEADER;
Definition: postgres_ext_defs.in.h:34