java/dbloader/src/main/java/be/bosa/dt/best/dbloader/CsvPreparer.java
/**
	 * Write addresses
	 * 
	 * @param xmlPath XML BeST directory
	 * @param csvPath CSV output directory
	 * @throws IOException 
	 */
Write addresses

@param xmlPath XML BeST directory
@param csvPath CSV output directory
@throws IOException
Write addresses @param xmlPath XML BeST directory @param csvPath CSV output directory @throws IOException
private void writeAddresses(Path xmlPath, Path csvPath, boolean gps) throws IOException {
		try(CsvWriter w = builder.build(csvPath.resolve("addresses.csv"), StandardCharsets.UTF_8)) {
			for (BestRegion reg: new BestRegion[] { BestRegion.BRUSSELS, BestRegion.FLANDERS, BestRegion.WALLONIA }) {
				LOG.log(Level.INFO, "Starting addresses {0}", reg.getName());
				int cnt = 0;
				AddressReader reader = new AddressReader();
				Stream<Address> addresses = reader.read(reg, xmlPath);
				Iterator<Address> iter = addresses.iterator();
				while (iter.hasNext()) {
					Address a = iter.next();
					Geopoint p = a.getPoint();
					Coordinate coordl72 = geoCoder.toCoords(p.getX(), p.getY(), false);
					Coordinate coordgps = geoCoder.toCoords(p.getX(), p.getY(), true);
					String x = String.valueOf(gps ? coordl72.x : coordgps.x);
					String y = String.valueOf(gps ? coordl72.y : coordgps.y);
					String c = geoCoder.toWkb(gps ? coordgps : coordl72);
					w.writeRow(NsConverter.addressEncode(a.getIDVersion()), 
						NsConverter.municipalityEncode(a.getCity().getIDVersion()),
						"1",
						NsConverter.municipalityPartEncode(a.getCityPart().getIDVersion()),
						"1",
						NsConverter.streetEncode(a.getStreet().getIDVersion()),
						"1",
						NsConverter.postalEncode(a.getPostal().getIDVersion()),
						"1",
						a.getNumber(), a.getBox(), "", 
						a.getStatus(), 
						(a.getFromDate() != null) ? a.getFromDate().toString() : "", 
						(a.getTillDate() != null) ? a.getTillDate().toString() : "", 
						(a.getBeginLife() != null) ? a.getBeginLife().toString() : "",
						(a.getEndLife() != null) ? a.getEndLife().toString() : "",
						c, "", "", "false");
					if (++cnt % 10_000 == 0) {
						LOG.log(Level.INFO, "Wrote {0}", cnt);
					}
				}
				LOG.log(Level.INFO, "Wrote {0}", cnt);
			}
		}
	}
private void writeAddresses ( Path xmlPath , Path csvPath , boolean gps ) throws IOException { try ( CsvWriter w = builder . build ( csvPath . resolve ( "addresses.csv" ) , StandardCharsets . UTF_8 ) ) { for ( BestRegion reg : new BestRegion [ ] { BestRegion . BRUSSELS , BestRegion . FLANDERS , BestRegion . WALLONIA } ) { LOG . log ( Level . INFO , "Starting addresses {0}" , reg . getName ( ) ) ; int cnt = 0 ; AddressReader reader = new AddressReader ( ) ; Stream < Address > addresses = reader . read ( reg , xmlPath ) ; Iterator < Address > iter = addresses . iterator ( ) ; while ( iter . hasNext ( ) ) { Address a = iter . next ( ) ; Geopoint p = a . getPoint ( ) ; Coordinate coordl72 = geoCoder . toCoords ( p . getX ( ) , p . getY ( ) , false ) ; Coordinate coordgps = geoCoder . toCoords ( p . getX ( ) , p . getY ( ) , true ) ; String x = String . valueOf ( gps ? coordl72 . x : coordgps . x ) ; String y = String . valueOf ( gps ? coordl72 . y : coordgps . y ) ; String c = geoCoder . toWkb ( gps ? coordgps : coordl72 ) ; w . writeRow ( NsConverter . addressEncode ( a . getIDVersion ( ) ) , NsConverter . municipalityEncode ( a . getCity ( ) . getIDVersion ( ) ) , "1" , NsConverter . municipalityPartEncode ( a . getCityPart ( ) . getIDVersion ( ) ) , "1" , NsConverter . streetEncode ( a . getStreet ( ) . getIDVersion ( ) ) , "1" , NsConverter . postalEncode ( a . getPostal ( ) . getIDVersion ( ) ) , "1" , a . getNumber ( ) , a . getBox ( ) , "" , a . getStatus ( ) , ( a . getFromDate ( ) != null ) ? a . getFromDate ( ) . toString ( ) : "" , ( a . getTillDate ( ) != null ) ? a . getTillDate ( ) . toString ( ) : "" , ( a . getBeginLife ( ) != null ) ? a . getBeginLife ( ) . toString ( ) : "" , ( a . getEndLife ( ) != null ) ? a . getEndLife ( ) . toString ( ) : "" , c , "" , "" , "false" ) ; if ( ++ cnt % 10_000 == 0 ) { LOG . log ( Level . INFO , "Wrote {0}" , cnt ) ; } } LOG . log ( Level . INFO , "Wrote {0}" , cnt ) ; } } }
Write addresses
Write addresses
// if GPS flag is set, write the WKB as GPS but x,y as Lambert72 (and vice versa) // calculate geom afterwards, using separate UPDATE statement